Lets discuss a basic c program
- Sum of two integers using c. This might be the first practice program for all users.
- To check sum of two integers , read input from user and store in two corresponding integer variables.
- Also take one more variable to store result of sum of two numbers
- c= a+b
- Print result using printf
- #include <stdio.h>
- // program to check sum of two numbers in c
- // write a c program to find sum of two integers
- // www.instanceofjava.com
- int main()
- {
- int x, y, sum;
- // read input from user
- printf(" Please enter any two numbers: ");
- scanf("%d %d", &x, &y);
- // sum of two numbers
- sum=x+y;
- printf("Sum of %d and %d is %d", x, y, sum);
- getch();
- }
Output:
- Please enter any two numbers
- 10
- 20
- Sum of 10 and 20 is 30
No comments