Header file:
stdlib.h
Synopsis:
int abs(int num);
Description:
It returns the absolute value(-ve to +ve) of the integer num.
abs function C example:
#include<stdio.h>
#include<stdlib.h>
int main() {
int no;
printf("Enter a number:");
scanf("%d", &no);
no = abs(no);
printf("Output: %d\n", no);
return 0;
}
#include<stdlib.h>
int main() {
int no;
printf("Enter a number:");
scanf("%d", &no);
no = abs(no);
printf("Output: %d\n", no);
return 0;
}
Output:
jp@jp-VirtualBox:~/cpgms/stdlib$ ./a.out
Enter a number:-123
Output: 123
Enter a number:-123
Output: 123
No comments:
Post a Comment