saving . . . saved Difference between two numbers has been deleted. Difference between two numbers has been hidden .
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 06-12-21, 11:09 p.m. Keerthi19

Answers:

Enter first number:5
Enter second number:10
Difference between 5 and 10 is=5

10-12-21, 11:31 a.m. hariharan110702@gmail.com


<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
24-01-24, 1:15 p.m. Vaishnavi2885


#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
05-08-24, 2:58 p.m. 238T1A05D9


#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;
}
    


05-08-24, 3:06 p.m. Nikki5D4


#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();
}
05-08-24, 3:09 p.m. 238T1A05D8


#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;
}
12-08-24, 2:41 p.m. 238T1A05D3


#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;
}
12-08-24, 3:07 p.m. tanmayi.P


#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
12-08-24, 3:18 p.m. 238T1A05G7


#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
16-08-24, 4:39 p.m. 238T1A05F5


#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
16-08-24, 4:39 p.m. 238T1A05F5


#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
19-08-24, 2:46 p.m. nasreensk2005@gmail.com


Log-in to answer to this question.