Lecture 5 3 1 More Examples On Nested Loops - Doc
Lecture 5 3 1 More Examples On Nested Loops - Doc
C program using nested loops (Serial numbers just to show you can study the logic of the program).
Example-1. Write a program in C using nested loops which has an output of 1-8 (newline) 2-9 (newline)
3-10 (newline) 4-11(newline) 5-12
1.
2.
3.
4.
5.
6.
7.
#include <stdio.h>
int
{
int
int
int
main(void)
a = 1;
b = 0;
c = 8;
8.
d
e
v
9.
10.
11.
12.
13.
14.
o
r
p
15.
16.
17.
p
A
18.
19.
20.
c++;
printf('\n');
}
printf("\n");
return 0;
345678910
4567891011
56789101112
Example-2
d
e
v
o
r
p
p
A
#include
Void
{
<stdio.h>
*/
main ( )
int i, j;
clrscr ( );
printf (\n);
}
}
==================================================================
* * * **
* * * **
* * * **
* * * **
EXAMPLE-3: PRINT SERIES FROM 10 TO 1 (10 LENES ARE REPEATED),
USING NESTED LOOPS ( USING FOR AND WHILE LOOPS).
#include
void main ()
o
r
p
{
int a;
p
A
clrscr ();
a=10;
for (k=1;k=10;k++)
{
while (a>=1)
{
printf ("%d",a);
a--;
}
printf("\n");
a= 10;
}
d
e
v
o
r
p
d
e
v
=====================================================
p
A