Program to Add Numbers
Add Numbers :
We will write a basic C program to add two Numbers for understanding basic structure of programming. In programming , we can add n numbers easily byy using proper syntax and algorithm.
Working of Program :
In the program, we will require two numbers from user to add and some basic operators to perform the calculation.
Run
#include<stdio.h> int main() { int a, b; printf("Enter first number :"); scanf("%d",&a); printf("Enter second number : "); scanf("%d",&b); int add =0; add = a+b; printf("Addition of a and b is : %d", add); return 0; }
Output :
Enter first number :2 Enter second number : 3 Addition of a and b is : 5
In the above program,
- scanf will take the input from the user.
- add variable is used to store the answer by applying the + operator
- printf will print the output on the screen
Example :
Let’s solve another problem by taking two decimal numbers from user.
Run
#include<stdio.h> int main() { float a, b; printf("Enter first number :"); scanf("%f",&a); printf("Enter second number : "); scanf("%f",&b); float add =0; add = a+b; printf("Addition of a and b is : %f", add); return 0; }
Output :
Enter first number : 5.0 5.0 Enter second number : 6.90 Addition of a and b is : 11.900000
What Happened Above?
In the above program, we take two decimal numbers from user and print the summation of them on the screen.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment