ccplusplus.com
Learn C, C++ Concepts
Saturday, January 14, 2012
c code to subtract two numbers without minus
/*********************************************************************** * File : subtract-without-subtraction-operator.c * Author : Saurabh Gupta * Desc : c code to subtract two numbers without minus * Source : http://ccplusplus/p/c.html * Created : PM 02:39 14 January 2012 ************************************************************************/ #include
int main(){ printf ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf ("subtract two number without using subtraction\n"); printf ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf ("\n"); int a,b; int nResult; printf ("Enter first number : "); scanf ("%d", &a); printf ("Enter second number: "); scanf("%d", &b); nResult = a + ~b + 1; printf("Difference of two numbers: %d\n", nResult); printf ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); return 0; } /* * OUTPUT * [sgupta@rhel6x64 c]$ gcc subtract-without-subtraction-operator.c -o subtract-without-subtraction-operator [sgupta@rhel6x64 c]$ ./subtract-without-subtraction-operator ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ subtract two number without using subtraction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enter first number : 20 Enter second number: 10 Difference of two numbers: 10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [sgupta@rhel6x64 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment