Q:

Write a C program to calculate difference of two numbers

0

Write a C program to calculate difference of two numbers. Here’s simple program to calculate difference of two numbers in C Programming Language.

In this program, Firstly, we are going to take input of two numbers from the user and then check for the condition which number is larger. After that, we use basic formula to calculate difference of two numbers i.e diff = num1 – num2;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C program to calculate difference of two numbers which is successfully compiled and run on Windows System to produce desired output as shown below :

SOURCE CODE : :

/*  C program to calculate difference of two numbers  */

#include <stdio.h>

int main()
{

    int a,b;
    int diff;

    printf("Enter first number :: ");
    scanf("%d",&a);
    printf("\nEnter second number :: ");
    scanf("%d",&b);

    // check condition to identify which is largest number
    if( a>b )
        diff=a-b;
    else
        diff=b-a;

    printf("\nDifference between %d and %d is = %d\n",a,b,diff);
    return 0;
}

 

OUTPUT : :

 

************** First Run ******************
    
Enter first number :: 6

Enter second number :: 2

Difference between 6 and 2 is = 4


************** Second Run ******************

Enter first number :: 7

Enter second number :: 45

Difference between 7 and 45 is = 38

Above is the source code for C program to calculate difference of two numbers which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Number Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program to find HCF of two numbers... >>
<< Write a C program to find power of a number ( x^n ...