For adding two numbers in c,we have to declare variables.
We can accept numbers from user also using scanf function or we can do it by declaring numbers to variables.
we will see both the methods.
Coding:
#include<conio.h>
#include<stdion.h>
void main()
{
int x=2,y=2,z;
/*here variables are of integer type which stores two bytes ,you can take it as float (decimal values) */
z=x+y;
printf("X: %d\n Y: %d \n Answer: %d",x,y,z);
/*accepting from user*/
printf ("Enter two numbers :");
scanf("%d%d",&x,&y);
z=x+y;
printf("X: %d\n Y: %d \n Answer: %d",x,y,z);
getch();
}
Output:

0 comments:
Post a Comment