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
Shamraj Babu.T
ECE Department
IRTT
C-and-Cpp Scope-Of-Variables 03-04 min 0-10 sec
Answers:
Dear User,
Please add semicolon(;) at the end of each scanf statement in this code.
#include <stdio.h>
int main(){
int a,b,diff;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
if( a>=b ){
printf("%d \n", diff=a-b);
}else{
printf("%d \n", diff=b-a);
}
return 0;
}
#include <stdio.h>
int main(){
int a,b,diff;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
if( a>=b ){
printf("%d \n", diff=a-b);
}else{
printf("%d \n", diff=b-a);
}
return 0;
}
#include <stdio.h>
int main(){
int a,b,diff;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
if( a>=b ){
printf("%d \n", diff=a-b);
}else{
printf("%d \n", diff=b-a);
}
return 0;
}
#include <stdio.h>
int main(){
int a,b,diff;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
if( a>=b ){
printf("%d \n", diff=a-b);
}else{
printf("%d \n", diff=b-a);
}
return 0;
}
Login to add comment