Professional Documents
Culture Documents
• Body – a statement or a
block of statements that
will be repeated.
• Condition – is used to
control the iteration –
either to continue or stop
iterating.
#include <stdio.h>
int main()
{
int i = 0;
while (i = 0)
printf("True\n");
printf("False\n");
return 0;
}
A. True (infinite time)
B. True (1 time) False
C. False
D. Compiler dependent
A. 1 2 3 4 5
B. 6
C. 5
D. Compiler error
10 9 8 7 6 5 4 3 2 1
Do TEN push ups = for
count=1; count<=10; count+
+
©LPU CSE101 C Programming
©LPU CSE101 C Programming
Q1
#include <stdio.h>
int main()
{
int i;
for (i = 1; i != 10; i += 2)
printf("Hello");
return 0;
}
A. Hello will be displayed 5 times
B. Hello will be displayed 4 times
C. Hello will be displayed infinite no. of times
D. Hello will be displayed 6 times
A. 1
B. 0
C. infinite loop
D. Nothing will be displayed
©LPU CSE101 C Programming
Q5
What will be the output of following code?
#include<stdio.h>
int main()
{
int i,j;
for(i=1,j=1;j<=5;j++)
{
}
printf("\n%d %d",i,j);
return 0;
}
A. 1 6
B. 1 1
C. 6 1
D. 1 5
…
}
}
• The above loop will run for 100*50 iterations.
Enter a number
4
The tables from 1 to 4
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12CSE101
©LPU 16 20 24 28 32 36 40
C Programming
#include<stdio.h>
int main() Program to
{
int i,j;
display a
printf(“Displaying right angled triangle for 5 pattern.
rows”);
for(i=1 ; i<=5 ; i++) {
for(j=1 ; j<=i ; j++)
printf(“* ”);
printf(“\n”);
}
return 0;
}
5-32
©LPU CSE101 C Programming
do…while statement
do
{
Repeated_Actions;
} while (Condition);
10 9 8 7 6 5 4 3 2 1
B. In while loop
In while loop