//add two number in c language

#include<stdio.h>

#include<conio.h>

void main()
{
int a=4,b=5,c=0;
c=a+b;
printf(“Sum=%d”,c);
getch();
}

output:

Sum=9

in this program we are using three variable a=4, b=5,c=0; you think about that why we use c=0 so you already know about memory. memory built-up various bit of cell each cell has own address if we are not assign with any value then variable automatic contains with address of cell it also know as garbage value.

then we use the c=a+b in this section the value of a and the value of b add and assign with c.

The print statement print the value and message. you must be know about value and message that how to print. in c language value and message always print in double quotes such as printf(“Sum=%d”,c); here Sum= is message and we are using %d that contains integer value, here %d contains integer value of c.

another example:

write a program to sum of three number

#include<stdio.h>

#include<conio.h>

void main()
{
int a=4,b=5,c=1,d=0;
d=a+b+c;
printf(“Sum=%d”,d);
getch();
}

output:

Sum=10

//subtract of two number in c language

#include<stdio.h>

#include<conio.h>

void main()
{
int a=4,b=5,c=0;
c=a-b;
printf(“Sub=%d”,c);
getch();
}

output:

Sub=-1

//multiply of two number in c language

#include<stdio.h>

#include<conio.h>

void main()
{
int a=4,b=5,c=0;
c=a*b;
printf(“Multiply=%d”,c);
getch();
}

output:

Multiply=20

//division of two number in c language

#include<stdio.h>

#include<conio.h>

void main()
{
int a=20,b=5,c=0;
c=a/b;
printf(“Sum=%d”,c);
getch();
}

output:

Div=4

Division / execute result as consent

Mode of two number

#include<stdio.h>

#include<conio.h>

void main()
{
int a=4,b=5,c=0;
c=a%b;
printf(“Mod=%d”,c);
getch();
}

output:

Mod=4

because % Modulus execute the result remainder

in this post we learn about + addition, – Subtraction, – Multiplication, / Division, % Modulus all five arithmetical operator used in program and all programs based on given value and now in next post we will learn how to input integer data, float data, character data and string data by user. Thankyou


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *