Sunday, October 5

Sum of Numbers

This is the most Basic Program of all time - "The sum of two numbers".



Source Code :


// Program Description :
// To calculate the sum of two numbers

#include<iostream.h>
#include<conio.h>

void main()
{
// cleaning the screen
clrscr();


// declaration of variables
float num1,num2,sum;


// input of values
cout<<"Enter the first number : ";
cin>>num1;
cout<<"Enter the second number : ";
cin>>num2;

// calculating the sum of numbers
sum=num1+num2;


// output the sum
cout<<endl<<"The sum of "<<num1<<" and "<<num2<<" is "<<sum<<endl;


// waiting for the user to analyse the output
cout<<endl<<"Press any key to quit...";
getch();

} // main ends here


Program Flow :



  • The message for entering the first number is displayed.
  • The user enters the number and presses Enter.
  • The message for entering the second number is displayed.
  • The user enters the second number and presses Enter.
  • The program calculates the sum of the numbers.
  • The sum of the numbers is displayed.
  • The program waits for user to Press any key to exit.

Output Screenshots :


A Screenshot of the program displaying the sum of 23 and 23 equal to 46

No comments:

Post a Comment