Home / Programs / Program to add two numbers
Programming Example

Program to add two numbers

👁 4,334 Views
💻 Practical Program
📘 Step by Step Learning
In this program we will add two floating point value (30.75 + 75.35). In case of floating point addition it will give decimal point value as a result.

Program Code

/* Programm ADDITION   */
/* Written by Rumman   */
#include"stdio.h" 
void main()   
{   
int number;  
float amount;   
 
number = 100;   
 
amount = 30.75 + 75.35;  
printf("%d\n \n",number);   
printf("%5.2f \n",amount);  
}   

Output

100

106.10
Press any key to continue . . .

Explanation

This Program is a example of 'Addition of Two Numbers'

Here 'number' is a 'int' type variable, which can contain integer number and 'amount' is 'float' type variable, which can contain floating numbers.

number=100; defines that 100 is assigned into 'number' variable.

amount = 30.75 + 75.35; defines that addition of 30.75 and 75.35 assigned into 'amount' variable.

printf("%d",number); , It is a print statement. Here we using predefined 'printf' function to print the value of 'number'. '%d' means "print an integer" and '%f' means "print an floating number". Here '%d' and '%f' are "format specifier", which identify the output of 'printf' function.

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.