In: Computer Science
What should be put in the blank position below in order to make the loop execute exactly 5 times? (C program)
int i ;
for ( i = 10 ; ______ ; i-- ){
printf ( "%d\n", i ) ;
}
Based on the condition in the question loop needs to execute 5 times.
So, We need to fill the blank position with i>5
Step1:
Initially the value of i is 10 then we check the condition i>5 if it is true then enter into the loop and print the i value.
Step2:
Next it decrement the i value i.e..(i--) and check the condition again I>5 if it is true then enter into the loop and print the i value.
Step3:
The loop will run till the condition is true i.e..(i>5). Once the i value less than or equal to 5 loop will be exit.
Code:
#include <stdio.h>
int main()
{
int i ;
for ( i = 10 ; i>5; i-- )
{
printf ( "%d\n", i ) ;
}
}
O/p:
10
9
8
7
6
As per the condition loop ran only 5 times.
Screenshots: