Subscribe Us

Addition Of Two Integer Numbers And Floating Numbers Using C programing - Sum of two number by c - smartduniya

 



C programming language is the most popular programming language in the world. All programmers starts their journey from the C programming language. C programmers are in high demand in IT. C programming is Basic of all programming language.

To add two numbers using C program, you need to add num1, num2, and the sum, but you can also float it. Your wish. We will then print the value using printf (). We then call Scanf () to get the value from the keyboard. Then we write a formula.

Sum = num1 + num2;

Then we come back to the function printf () to print the answer to what we got..

That's it.

At first we will learn how to add two integer number.It is very simple program.

Let's start..


Addition Of Two Integer Number :

An example;

we put num1 =100 and num2 =100 and get result is 200..

see below How to do.?




/* This program Add two Integer Number and give us result Two number input through the keyboard; example ; num1 = 100 ; num2 = 100 ; result = 100+100= 200; Best Sellers in Computers & Accessories */ #include <stdio.h> // #include is pre-processer and <stdio.h> is header file int main() // main () is a function { /* start code */ // printf() is used for print anything. // scanf () is used for take input from user int num1,num2,result; /*By this line we say the compiler that num1, num2,result all are integer.... int means integer */ printf("Enter Number1 : ") ; // user enter first number scanf("%d",&num1); // first number store in num1 , %d is used for integer value printf("\n Enter Number2 : ") ; // user enter second number scanf("%d",&num2); // Second number store in num1 , %d is used for integer value result=num1+num2; // add num1 & num2 and store the value in result

 

printf("Your Result is : %d",result); // here we print the result value return 0; }





Write this code on your compiler (tubro c++ , Dev c++,.etc )  and save it in 

'.c ' extension .

Then compile And run the program. 

When you run this you see the window 




 You have to Enter Number 1  and then press enter you get a next window here you have to put Second number  and then press enter  you get your result. 



I hope you run this program properly. If you face any problem comment below .

see next one ,

Addition Of Two Floating Number :

An example;

we put num1 =99.999 and num2 =0.001 and get result is 100..

see below How to do this .?


/* This program Add two Integer Number and give us result Two number input through the keyboard; example ; num1 = 99.999 ; num2 = 0.001 ; result = 99.999+0.001= 100.000; */ #include <stdio.h> // #include is pre-processer and <stdio.h> is header file int main() // main () is a function { /* start code */ // printf() is used for print anything. // scanf () is used for take input from user float num1,num2,result; /*By this line we say the compiler that num1, num2,result all are float.... float means floating value */ printf("Enter Number1 : ") ; // user enter first number scanf("%f",&num1); // first number store in num1 , %f is used for floating value printf("\n Enter Number2 : ") ; // user enter second number scanf("%f",&num2); // Second number store in num1 , %f is used for floating value result=num1+num2; // add num1 & num2 and store the value in result printf("Your Result is : %f",result); // here we print the result value return 0; }

 Output: 




 Write this code on your compiler (tubro c++ , Dev c++,.etc )  and save it in 

'.c ' extension .All process are remain same . 

Then compile And run the program. 

When you run this you see the window 



Then press Enter after input first number and then give second number and hit enter button



you get your result  . ....




If you face any problems comment below. I will help you.



Post a Comment

0 Comments