Hi there!
The Sum and subtraction of two numbers is a basic program in the C language.
Firstly, we need to initialize two variables along with data type int a,b, after that we need to read or assign
values to two numbers, then perform an athematic operation using athematic operator using like +, -, %,*
a+b or a-b between two variables and assign the value of operation to a new variable like c=a+b
for better understanding let's see the algorithm of the program
Algorithm of the sum of two numbers
Step 1: Start
Step 2: Read values a and b
Step 3: Add a and b and assign the result to sum
Sum<-a+b
Step 4: Display sum
Step 5: Stop
Program
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter a number : ");
scanf("%d",&a);
printf("enter a number :");
scanf("%d",&b);
c=a+b;
printf("Given numbers :%d,%d",a,b);
printf("sum of two numbers are :%d",c);
getch();
return 0;
}
Output
To find the subtraction of the two numbers just replace the + with -.
Algorithm of subtraction of two numbers
Step 1: Start
Step 2: Read values a and b
Step 3: Add a and b and assign the result to sum
Sum<-a-b
Step 4: Display sum
Step 5: Stop
Program
#include
#include
int main()
{
int a,b,c;
printf("enter a number : ");
scanf("%d",&a);
printf("enter a number :");
scanf("%d",&b);
c=a+b;
printf("Given numbers :%d,%d",a,b);
printf("sum of two numbers are :%d",c);
getch();
return 0;
}
Output
ok, if you have any doubt feel free to contact us. if you want any program in C language please comment we will try our level best.
Thank you for visiting.




0 Comments