Calculate difference of two numbers
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;
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 .
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post….
#include<stdio.h>
#include <math.h>
int main()
{
printf(“enter numbers :\n“);
float a,b;
scanf(“%f%f“,&a,&b);
float c = fabs(a–b);
printf(“the result is %f\n“, c);
return 0;
}