Reputation: 13
so basically I wrote this code to print the greater number but it is not working.I am new to C and this confuses me a lot
#include <stdio.h>
int greater(int a, int b);
int main()
{
int a,b,x;
printf("\n Enter two numbers:");
scanf("%d %d ",&a, &b);
x=greater(a, b);
printf("\n The greatest number is:%d", x);
return 0;
}
int greater(int x, int y)
{ int great;
if(x>y){
great=x;
}
else
{
great=y;
}
return great;
}```
Upvotes: 1
Views: 42
Reputation: 41017
The problem is the trailing white space in scanf
, switch to:
printf("\n Enter two numbers:");
scanf("%d %d",&a, &b);
x=greater(a, b);
See why: What is the effect of trailing white space in a scanf() format string?
Upvotes: 2