This blog is under construction

Monday 30 April 2012

abs example in C

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;
  }
 


  Output:
  jp@jp-VirtualBox:~/cpgms/stdlib$ ./a.out
  Enter a number:-123
  Output: 123


No comments:

Post a Comment