Pages

How to add two values enterd by user.

//How to add two values enterd by user.


#include<stdio.h>
#include<conio.h>
void main()
{
  int num1,num2,sum;  //declare a integer varaiable
  clrscr();   //clear the screen
  printf("Enter the first number of an integer:");  //Show the message to user
  scanf("%d",&num1);  //Store the value entered by user in variable num1.
  printf("Enter the second number of an integer:");  //Show the message to user
  scanf("%d",&num2);  //Store the value entered by user in variable num2.
  sum=num1+num2;
  printf("Sum:%d",sum); //Sum of two numbers
  printf("\nAlso show sum of two integer numbers in other way:");
  printf("\n%d + %d = %d",num1,num2,sum);
  getch();   //Hold the screen for output
}

Output:

Enter the first number of an Integer:45
Enter the second number of an integer:25
Sum:70
Also show sum of two integer numbers in other way:
45 + 25 = 70

No comments:

Post a Comment