w3resource logo

:

C Programming Exercises

C Exercises: Return the absolute value of an integer

C Variable Type : Exercise-16 with Solution

Write a C program to return the absolute value of an integer.

Sample Solution:

C Code:

#include<stdio.h>
#include<stdlib.h>

int main ()
	{
		int num;
		printf("\n Input a positive or negative number :");
		scanf("%d",&num);
		printf (" The absolute value of the given number is : %d\n\n",abs(num));
		return 0;
	}

Sample Output:

 Input a positive or negative number :-25                                                                     
 The absolute value of the given number is : 25 

C Programming Code Editor:

Improve this sample solution and post your code through Disqus