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.
The following program will add two int
numbers and prints sum
on the output screen.
#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.
}
The following program will also add two integer
numbers and
print sum on the output screen.
#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.
}
The following program will also add two integer
numbers and
print sum on the output screen.
#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();
}
The following program will also add two integer
numbers and
print sum on the output screen.
#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();
}
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.
#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();
}