Difference between two numbers
Title
Question
#include<stdio.h>
int main( )
{
int a,b;
int diff;
printf("Enter first number :");
scanf("%d",&a);
printf("Enter second number :");
scanf("%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("\n Difference between %d and %d is=%d",a,b,diff);
return 0;
}
By
Keerthi vennila S
Ece department
Irtt
C-and-Cpp Scope-Of-Variables 05-06 min 40-50 sec
Answers:
Enter first number:5
Enter second number:10
Difference between 5 and 10 is=5
<font size="4">Program in c to print the difference of two numbers:</font>
#include <stdio.h>
int a=7;
int b=5;
void difference()
{
int sub;
sub = a - b;
printf("Difference of a and b is %d\n",sub);
}
int main()
{
difference();
return 0;
}
Output:
Difference of a and b is 2
Program in cpp to print the difference of two numbers:
#include <iostream>
using namespace std;
int a=7;
int b=5;
void difference()
{
int sub;
sub = a - b;
cout<<"Difference of a and b is "<<sub <<"\n";
}
int main()
{
difference();
return 0;
}
Output:
Difference of a and b is 2
Login to add comment