Program to print addition
of 2 user numbers
Let’s see how to write this
C program
#include<conio.h>
#include<stdio.h>
int main()
{
int fnum,snum,result;
printf("enter
first number ");
scanf("%d",&fnum);
printf("enter
second number ");
scanf("%d",&snum);
result=fnum+snum;
printf("result
=%d",result);
getch();
return 0;
}
Explanation
of the program
int
fnum,snum,result;
Here we
initialize our 3 variables named as fnum,snum and result. These variable currently holds no value.
printf("enter
first number ");
use to print as it is on the screen “enter first number“.
scanf("%d",&fnum);
allow user to enter any desired value
in fnum variable.
printf("enter
second number ");
use to print as it is on the screen “enter second number“.
scanf("%d",&snum);
allow user to enter any desired value
in fnum variable.
result=fnum+snum;;
in this
statement we add up the values of fnum
and snum and then we pass that value
to the variable result. Now result is holding up the addition of fnum and snum variable.
printf("result
is = %d",result);
this will
going to display the value stored in the variable result.
In this we
combine it with the string as firstly it will display the
“result is = “
Then the
value of result is being displayed.
%d
This tells
the compiler that we are going to display or read the value of integer type.
Getch(); and
return 0;
We already
discussed this click here to move back.
Pictures of program:
Step 1: Create the program:-
Step 2: output
Note: if any of the programmer is facing the
problem of reappearing of the previous screen again and again
He can use the function
clrscr();
It present in the
conio.h header file
After declaring the
variables
No comments:
Post a Comment