The program is designed to add two (2) numbers/integers using the basic mathematics and C language commands. Check out the codes below.
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("Enter number: ");
scanf("%d", &a);
printf("\nEnter number: ");
scanf("%d", &b);
c = a + b;
printf("\nThe sum is %d", c);
getch();
}
In this program, we simply follow the rules of mathematics in adding numbers. As shown above, c = a + b illustrates the addition equation. Variables a and b holds the numbers entered by the user. While, variable c holds the sum of the numbers. Please note that the variables declared are used with a data type int which means it only accepts whole numbers. Check out the sample output below.
Hope you learned something from this post. Thanks!
No comments:
Post a Comment
Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!