Why the result "oo" has putted first and why value of c is showing 5 .? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why the result "oo" has putted first and why value of c is showing 5 .?

Problem is in this code ⬇️ https://code.sololearn.com/cj0CpYYN4Ld8/?ref=app

2nd Jan 2021, 4:31 AM
RD:programmer
RD:programmer - avatar
6 Answers
+ 3
because in your function "sum", the "oo" is already printed before you even return the value (1) Declared int a = 5; (2) Calls the function (3) Condition is false so else statement is executed (4) Since else is executed "printf("oo")" will also be executed (5) Returns the value of a (which was not changed and still 5) to the variable "c". (6) Prints "the number is 5" Output: >> oothe number is 5
2nd Jan 2021, 4:40 AM
noteve
noteve - avatar
+ 2
The value is of c is 5 since you are returning that value (return(a) and value of a is 5 therefore c=5). And of 'oo' since a/2!=0 which is 5/2!=0 but 5/2=2 if condition is returned false therefore else is runned and we got "oo" as output and it is printed first since it is before you return any value.
2nd Jan 2021, 4:42 AM
Sanjyot21
Sanjyot21 - avatar
+ 2
Mr. Unknown Create void function if you only want to print something and not return values. See this code. https://code.sololearn.com/ck5N7vlbgzp0/?ref=app
2nd Jan 2021, 5:26 AM
noteve
noteve - avatar
+ 2
ধন্যবাদ thanks to all community ..... Here I gain what I want ⬇ thanks again https://code.sololearn.com/cAtu4X3Km0Vb/?ref=app
3rd Jan 2021, 5:18 AM
RD:programmer
RD:programmer - avatar
0
So now what I do if I want only "o" or "oo".... using function
2nd Jan 2021, 5:03 AM
RD:programmer
RD:programmer - avatar
0
Mr. Unknown just put if condition as a==5
2nd Jan 2021, 5:06 AM
Sanjyot21
Sanjyot21 - avatar