C program to take input for two numbers calculate and print their sum, product, and difference

Problem In Hand

C Program to take input for two numbers calculate and print their sum, product and difference

Process and Solution Of Problem

Take input for two numbers and store them in two variables
calculate and store sum of the numbers in a third variable
calculate and store product of the numbers in a forth variable
calculate and store difference of the numbers in a fifth variable
further display sum ,product, difference

Program/Source Code

#include <stdio.h>
 int main()
 {
     int a,b,s,p,d;
     printf("Enter 2 nos ");
     scanf("%d %d",&a,&b);
     s=a+b;
     p=a*b;
     if(a>b)
         d=a-b;
     else
         d=b-a;
     printf("Sum = %d  prod = %d  diff = %d",s,p,d);
 return 0;
 }

Program Explanation

On execution of the program

* user enteres the first number and it is stored in a variable “a”
* user enteres the second number and it is stored in a variable “b”
* Calculation is performed and sum of values is stored in a variable “s” i.e. s=a+b;
* Calculation is performed and product of values is stored in variable “p” i.e. p=a*b;
* Calculation is performed and difference of values is stored in a variable “d” i.e. d=a-b;
* then the result is displayed on the screen

Output:

 ex:1
 Enter 2 nos 10
 20
 Sum = 30  prod = 200  diff = 10
 ex:2
 Enter 2 nos 10
 5
 Sum = 15  prod = 50  diff = 5 

You May Also Like:

C Program to find largest of 3 numbers
C Program to print table of a number
C program to check number is +ve, -ve or zero
C program to check number is prime number or not
C program to convert total inches to feet and inches.


<<< Previous: Square and Cube of a NumberArea and Perimeter of square : Next >>>

All Programs      C Simple Programs      If Condition Programs      Switch Statement Programs      Loop Programs       Conversion Programs      Pattern Programs       Single Dimension Numeric Array programs       Double Dimension Numeric Array programs      Single Dimension Character Array programs

Tutorials

Technical Questions

Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions


Number Of Visitors

0238199