Header Ads Widget

Use of abs() function in c.

Use of abs function c :-

                                       abs() is a predefine function present in stdlib.h header file in c. It gives always positive value of a number.

Example:-

              abs(-4)=4
               abs(4)=4
              abs(-89)=89

program:-

 #include<stdio.h>
#include<stdlib.h>
int main()
{
    int num,new_num;
    printf("Enter a number\n");
    scanf("%d",&num);
    new_num=abs(num);
    printf("New number is %d",new_num);
    return(0);

input:-

Enter a number
 -98                  

output:-

 New number is 98

Post a Comment

2 Comments