C programs

C Program for Subtraction of two Numbers

Here is a simple program of Subtraction of two numbers. In this program input taken dynamically from user and perform Subtraction of two number and show result to user. To perform Subtraction need to use arithmetic operator  -.




void main()


int a,b,c;//variable declaration


printf("enter first number:\t");// Accept first number from user

scanf("%d",&a); // address of first variable

printf("enter second number:\t");// Accept second number

scanf("%d",&b); // address of  second variable

c=a-b; // sub two numbers

printf("answer=%d\n",c); // print result



When Run The Program Following Output:

enter first number:   40

enter second number:  20



In above program input taken from user at run time using scanf()

Perform  Subtraction  using the statement c=a-b;

result is saved in variable c

To print Subtraction result printf("ans=%d\n",c)   is used.

The // symbol used to give comments in program to understand the code to human, That does not effect on program it is only for user to understand program.

Releted Programs

© 2017 codewmAll rights reserved.