Add two numbers in C

Add two integer numbers using different ways in C programming and print the sum on the output screen. In this tutorial, you will learn how to add two numbers.

Program Adding Values

The following program will add two int numbers and prints sum on the output screen.

Program

        #include<stdio.h>
        #include<conio.h>
        void main()
        {
        printf("The Output is: %d", 5 + 6); //adding 5 and 6 and printing.
        getch();            //it printing Answer on '%d' area.
        }
Output
The Output is: 11

Program Adding Two Values

The following program will also add two integer numbers and print sum on the output screen.

Program

#include<stdio.h>
#include<conio.h>
void main()
{  //U also write like 'int a = 5, b = 6, c;'.
int a, b, c; //declaring 'a', 'b' and 'c' for Integers values.
a = 5; //assigning 5 to 'a'.
b = 6; //assigning 6 to 'b'.
c = a + b; //adding 'a' and 'b' values and assigning to 'c'.
printf("The output is: %d", c); //printing 'c' value, U also write like 'printf("%d",a + b);'
getch();         //if U write then dont write 'c = a + b;' this.
}
Output
The output is: 11

Program Adding Two Values Another Method

The following program will also add two integer numbers and print sum on the output screen.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a = 5; //assigning 5 to 'a'.
int b = 6; //assigning 6 to 'b'.
int c = a + b; //adding 'a' and 'b' values and assigning to 'c'.
printf("The output is: %d", c); //printing 'c' value.
getch();
}
Output
The output is: 11

Program Adding and printing Values

The following program will also add two integer numbers and print sum on the output screen.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
a = 50;
b = 25;
c = a + b;
printf("The sum of %i and %i is %i\n", a, b, c); //printing values and Sum.
getch();
}
Output
The sum of 50 and 25 is 75

Program Adding and Printing Declaring Global

when U declare variable Before Main void main() and after Library then called Global Variable Declaration.
And when U declare variable After Main void main() and Inside any Body then called Local Variable Declaration.

Program

#include<stdio.h>
#include<conio.h>
int a, b, c; //declaring 'a', 'b' and 'c' as a Global variable.
void main()
{
a = 50;
b = 25;
c = a + b;
printf("The sum of %i and %i is %i\n", a, b, c); //printing values and Sum.
getch();
}
Output
The sum of 50 and 25 is 75