Q8 Write a program to find the absolute value of a number entered through the keyboard

Write a program to find the absolute value of a number entered through the keyboard

Program: 76

Write a c program to find the absolute value of a number entered through the keyboard.

#include<stdio.h>
#include<conio.h>
int main()
{
    int n, num;

    printf("Enter a number: ");
    scanf("%d", &n);
    num = n;
    //first method
    if(num<0)
    {
        num = (-1)*num;
    }
    //second method
    //num = abs(num);

    printf("The absolute value of %d is %d",n , num);
    return 0;
}

Output:

 Enter a number: -12
The absolute value of -12 is 12
Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.

View Comments (1)

Related Post
Leave a Comment

This website uses cookies.