ADDITION OF TWO NUMBERS
SIMPLE C LANGUAGE CODE FOR ADDITION OF TWO NUMBERS:
#include<stdio.h>
#include<conio.h>
int main()
{int a, b, c;//we take two integer value
printf("Enter the number :");//use to print the letter, character
scanf("%d%d",&a,&b);//use to scan the accept number and scan it
c=a+b;//arithmetic logical operation, formula
printf("Ans=%d\n", c)/*use to perform operation and display answer*/
getch();
}
And save with extension .c
for eg.
add.c//add is the name of the file and .c is an extension of the file.
In the above example, we can add integer numbers not fractional numbers. for example when output screen comes type two numbers like 2 and press enter then type next numbers like 6 then press enter the answer print on the output screen.
This code is for integer numbers, if we want to add fractional numbers then in above code small changes is there i.e.in the place of int type float and at the place of % d type % f.For addition of fractional numbers the code is as follow:
ADDITION OF TWO FRACTIONAL NUMBERS:
#include<stdio.h>
#include<conio.h>
float main()
{flaot a, b, c;//we take two fractional value
printf("Enter the number :");//use to print the letter, character
scanf("%f%f",&a,&b);//use to scan the accept number and scan it
c=a+b;//arithmetic logical operation, formula
printf("Ans=%f\n", c)/*use to perform operation and display answer*/
getch ();
}
In a previous blog I said that many types of comment is there in that other type is/* */. This is used to give the multiline comments for example.
printf("Ans=%f\n", c)/*use to perform operation and display answer*/
I hope you like my blog so if any queries is there then write in comment box.I will solve it.Friends in next blog I will teach you the another program.
YOU MUST LEARN C FOR EFFECTIVE FUTURE |
C language code for addition of two numbers
Reviewed by Amit Waghmare
on
September 14, 2018
Rating:
No comments: