Lecture 6Part2Looping Statements - or - Iterative Statements
Lecture 6Part2Looping Statements - or - Iterative Statements
#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
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-26
©LPU CSE101 C Programming
Difference between while and do..while
while loop do..while loop
1. Condition is specified at the top 1. Condition is mentioned at the
bottom
2. Body statements are executed 2. Body statements are executed at
when the condition is satisfied least once even if the expression value
evaluates to false
3. It is an entry controlled loop 3. It is an exit controlled loop
4.Syntax: 4.Syntax:
while (condition) do
statement; {
statements;
}
while (condition);
B. In while loop
In while loop