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
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,diff;
printf("enter a value :");
scanf("%d",&a);
printf("enter b value :");
scanf("%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference between %d and %d =%d", a,b,diff);
getch();
}
output:
enter a value :5
enter b value :3
difference between 5 and 3 is 2
#include<stdio.h>
int main()
{
int a, b, diff;
printf("enter a value:");
scanf("%d", &a);
printf("enter b value:");
scanf("%d", &b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference between %d and %d=%d", a,b,diff);
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b ,diff;
printf("enter the a and b values");
scanf("%d%d",&a&b);
if(a>b)
{
diff=a-b;
printf("diff=%d:,diff);
}
else
{
diff=b-a;
printf("diff=%d",diff);
}
getch();
}
#include<stdio.h>
int main()
{
int a, b, diff;
printf("enter a value:");
scanf("%d", &a);
printf("enter b value:");
scanf("%d", &b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference between %d and %d=%d", a,b,diff);
return 0;
}
#include<stdio.h>
int main()
{
int a, b, diff;
printf("enter a value:");
scanf("%d", &a);
printf("enter b value:");
scanf("%d", &b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference between %d and %d=%d", a,b,diff);
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,diff;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf(:%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference=%d",diff);
getch();
}
output
enter a value:7
enter b value:3
difference=4
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,diff;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf(:%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference=%d",diff);
getch();
}
output
enter a value:8
enter b value:4
difference=4
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,diff;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf(:%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference=%d",diff);
getch();
}
output
enter a value:8
enter b value:4
difference=4
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,diff;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf(:%d",&b);
if(a>b)
diff=a-b;
else
diff=b-a;
printf("difference=%d",diff);
getch();
}
output
enter a value:10
enter b value:5
difference=5
Login to add comment