Addition of two numbers in C [Best Method]

Welcome friends… Today, we will understand a program “Addition of two numbers in C“.

How you can implement this program code in an easy way. This is the easiest method by which you can write your program code to add two numbers in C.

Here, I am taking integer numbers but you can use float as well as other data types to add two numbers in c language.

Similarly, if you are using C++, So you can use the same method that I am using here.

So, Let’s get started.

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c; //variable declaraction 
clrscr(); // clears the console screen
printf("Enter value of a:");
scanf("%d",&a); //input value of a
printf("Enter value of b:");
scanf("%d",&b); //input value of b

c=a+b; //addition of a and b
printf("Sum of two numbers is:%d",c); //display result
getch();
}

Program Code Explanation (PCE)

Printf(): It is the output function that displays the text/message on console screen as it is. You can also use it to display the value of any variable(s) using control strings(e.g. %d,%f,%ld etc).

Scanf(): It is the input function that takes input from the user and put that value into a variable. It also uses control strings as per variable declaration.

Other useful post

I hope that you understand the addition of two numbers in C. If you have any questions related to C programming, comment below.

Please share the program code to your friends so that they can also get a benefit.

If you want to learn more about blogging read my other blog here

Leave a Comment

Show Buttons
Hide Buttons