- 1

Why this code showing no ouptput

#include <stdio.h> int main() { int num = 5; while (num > 0) { if (num == 3) continue; num--; printf("%d\n", num); } } EDIT : SOLVED

4th Aug 2021, 7:56 AM
Abhinraj
13 odpowiedzi
+ 3
The code would print 4 3 and then loop inifinitely. During run time Sololearn redirects the output to a file. Normally when the program finishes, Sololearn displays the output file. But because your process has to be killed due to exceeding its time limit, the file is forced closed before the cached write occurs. So the output file is empty.
4th Aug 2021, 3:08 PM
Brian
Brian - avatar
+ 5
if num==3, it is stuck in infinite loop. You may want to put num-- before if num==3 to see the output !!
4th Aug 2021, 7:58 AM
Abhay
Abhay - avatar
+ 3
Abhinraj maybe it has something to do with sololearn .
4th Aug 2021, 12:06 PM
Abhay
Abhay - avatar
+ 2
It seems your code doesn't want to output anything:) Abhay is right. while(num>0) if ((num--)!=3) printf("%d\n",num+1)
4th Aug 2021, 9:39 AM
▬▬▬
▬▬▬ - avatar
+ 2
Abhinraj while (num) works; no need of the 'num > 0' part.
5th Aug 2021, 6:45 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas ..yes u r right.thanks
5th Aug 2021, 6:51 AM
Abhinraj
0
Okk...then 'no output' showing because of run time error ?
4th Aug 2021, 8:01 AM
Abhinraj
0
Bro it showing "No Output"
4th Aug 2021, 8:07 AM
Abhinraj
0
Brian Thanks ✨.now it is clear
4th Aug 2021, 5:48 PM
Abhinraj
0
Thanks guys ✨
4th Aug 2021, 5:49 PM
Abhinraj
0
Yes after printing 4 3 while loop in infinite time .so num-- write before if conditions
6th Aug 2021, 2:22 AM
Ankit Kumar
Ankit Kumar - avatar
0
while (num>0) num-- if(num==3) continue; printf ("%d",num); Output-4 2 1
6th Aug 2021, 2:24 AM
Ankit Kumar
Ankit Kumar - avatar
6th Aug 2021, 2:27 AM
Abhishek Kumar
Abhishek Kumar - avatar