Revision 7nested Loops

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Revision 7

1. Write C++ program/ programs to reproduce each of the shown output:

* ********** * 0
** ********* *** 01
*** ******** ***** 012
**** ******* ******* 0123
***** ******
********* 01234
****** ****
******* *** *********** 012345
******** ** ************* 0123456
********* *

1 0 0 0 0 0 1 2 3 4
0 1 0 0 0 0 5 6 7 8
0 0 1 0 0 0 9 10 11 12
0 0 0 1 0 0 13 14 15 16
0 0 0 0 1 0
0 0 0 0 0 1

2. Show the output of each of the following program segments:

a-
#include <iostream.h>

int main ()
{
int n=0;

for (int i=0; i<7; i++)


{
for (int j=0; j<=n; j++)
{
cout<<j;

}
n++;
cout<< endl
}

=======================================================================
b-

#include <iostream.h>

int main ()
{
int n=1 , j=1;

for (int i=0; i<4; i++)


{
for (int k=j; k<=n*4; k++)
{
cout<<k;

}
n++;
j=j+4;
cout<< endl
}

c-

#include <iostream.h>

int main ()
{
int i=1;

while(i <= 128)


{
for (int k=0; k<4; k++)
{
cout<<i;
i=i*2;

cout<< endl
}

You might also like