Addition of two numbers

Program Description

Take two numbers from the user (integer values) and display their sum

Program
/*******************************************************************
*
* code.cheraus.com
*
*  A simple program for addition of two numbers. Asks the user for two
*  integers and outputs their sum. Does not deal with float values.
*
********************************************************************/

#include<stdio.h>
int main()
{
 int num1=0;      //integer variable to hold first number
 int num2=0;     //integer variable to hold second number
 int num3=0;     //integer variable to hold the sum

 printf("Enter the first number: ");    //prompts the user for input 
 scanf("%d",&num1);                     //takes the input from keyboard

 printf("Enter the second number: ");   //prompts the user for second number
 scanf("%d",&num2);                     //takes the asecond input from the user

 num3=num1+num2;                       //perform addition and saves the result in num3

 printf("\nThe addition of the two numbers is %d\n",num3);  //prints the result

 return 0;                           // returns from the program indicating successful run

}

Output
Test Case 1:

Enter the first number:3
Enter the second number:2
The addition of the two numbers is 5

Test Case 2:

Enter the first number:-1
Enter the second number:2
The addition of the two numbers is 1

Comments
comments powered by Disqus