why is my code not giving the proper output?Can anyone provide a hint?

Presika Subedi

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;
    
}```
David Ranieri

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?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

why is my code giving me a settext error?

Why is my code giving different answers on Online Judge and locally?

Can anyone tell me, why my js code is not running on jsfiddle?

Why is my code giving memory error?

Why my piglatin translator code is giving unexpected output?

Why is my line of code giving the wrong character location in a string

Does anyone know why res.download is giving my download file a random name each time?

Don't understand why my code giving me an IndexError

My JavaScript If-Statement code is not giving the proper result when user enters his name in prompt

Why is my code in python not giving an output at all?

Why using await is also giving a pending promise in my code?

how to ensure proper indentation in datas ifstreamed from a file. Look at my code , it's not giving desired results

Why my code giving me a stackdump error when I run it?

Why is my code giving incorrect results for big numbers?

Why is my code giving Runtime Error?

Why is my code giving IOException (System could not find the file specified)?

Can anyone explain why my date function is giving me a wrong conversion via JS date object?

Why my Linqued query is not giving me proper result?

Why my json_encode is not giving proper value in PHP

ANYONE CAN TELL ME THAT WHY THIS CODE IS GIVING ME AN ERROR OF TABLE OT CLUSTER KEY WORD IS MISSING?

why max function does not print proper output in my code?

Can anyone hint at a way to recall my iterated labels in kivy?

Why is my python code giving wrong answers for only some inputs?

Why my code is giving Time Limit Exceeded?

Why is my code not giving any output even though there is no error in the code?

My code is not giving proper out put on offline compilers?

Why my code is giving error after i submit code

Can anyone make me understand why visual studio is giving me this warning for my c++ code?

Why is my code giving segmentation fault error?