ccplusplus.com
Learn C, C++ Concepts
Monday, October 10, 2011
absolute value of a number in c
/************************************************************* * File : absolute-value-of-number.c * Author : Saurabh Gupta * Desc : absolute value of an integer * Source : http://saurabhgupta0527.blogspot.com/p/c.html * Created : PM 10:48 10 October 2011 ************************************************************/ #include
void main() { int nNumber, nTemp; printf("enter the Number : "); scanf("%d",&nNumber); if(nNumber < 0) { nTemp=nNumber*-1; printf("\nabsolute value of %d = %d\n",nNumber,nTemp); } else { printf("\nabsolute value = %d\n",nNumber); } } /* * OUTPUT * absolute value of -10gcc absolute-value-of-number.c -o absolute-value-of-number [sgupta@rhel6x64 c]$ ./absolute-value-of-number enter the value of a : -10 absolute value of -10 = 10 [sgupta@rhel6x64 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment