Professional Documents
Culture Documents
By
Pundreekaksha Sharma
Assistant Professor
CSE Deptt
• 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.
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
Program to find sum of first n numbers
#include<stdio.h>
int main()
{
int n,i,sum=0;
printf("enter the value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("the sum=%d",sum);
return 0;
}
}
printf("the sum of digits=%d",sum);
}
…
}
}
• 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-28
©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