Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
I was asked this question recently.
In C, with the help of one printf statement, find the greater of 2 numbers say A & B.

I used ternary operator; although it contained two printf statements.

Can you guys help?
Posted

1 solution

Try this:

C
int A = 5;
int B = 6;

printf("%i", A > B ? A : B);
 
Share this answer
 
v2
Comments
abhinash guha 22-Sep-15 10:50am    
isnt it ternary operator? The requirement is 1 printf only.
CHill60 22-Sep-15 10:52am    
There *is* only a single printf in this solution!
abhinash guha 22-Sep-15 10:54am    
yeah ok
abhinash guha 22-Sep-15 10:57am    
:) thank you
Leo Chapiro 22-Sep-15 11:00am    
You are welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900