Program
to print addition of 2 default numbers
Let’s see how to write this
C program
#include<conio.h>
#include<stdio.h>
int
main()
{
int first=
10,second=12;
int
result;
result =
first+second;
printf("result
is = %d",result);
getch();
return 0;
}
Explanation of the program
Int
first=10,second=12;
This
statement we going to initialize the two variables in the memory named as first and second which holds the default values of 10 and 12 respectively.
int
result;
Here
we initialize our 3rd variable named as result. This currently holds no value
result=first+second;
in
this statement we add up the values of first
and second and then we pass that
value to the variable result. Now result is holding up the addition of first and second 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 the value of integer variable
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