Nested Loops: ND RD TH TH
Nested Loops: ND RD TH TH
NESTING is the process of placing one or more loop structures inside the body of another loop structure. The inner loop is evaluated first. For one iteration of the outer loop, all iterations of the inner loop must be finished first before the outer loop can process its next iteration. When the inner loop is reentered, the inner loops variable is reset to its initial value. Ex. 1.) Write a program segment to print the numbers 1 to 20 in a 4 x 5 matrix shown below : a.) 1 6 11 16 2 7 12 17 3 8 13 18 4 9 14 19 5 10 15 20 b.) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
2.)Give the output of the following program segment : int x, y; for(x= 1; x<= 5; x++) { for (y = 1; y <=x ; y++) cout<<"*"; cout<<endl; }
4.)Write a program segment that will print in tabulated format the 2nd, 3rd, 4th and 5th power of numbers, from 1 to N, where N is to be entered from the keyboard. Print first the header of each tabulated column. double x, y; int N; cout<<"Enter the value for N :"; cin>>N; cout<<"N \t N^2 \t N^3 \t N^4 \t N^5 \n"; for(x= 1; x<= N; x++) { for (y = 1; y <=5 ; y++) cout<<pow(x,y)<<" \t "; cout<<endl; }
5.) Write a program that will print the Multiplication Table for numbers from 1 to N, where N is a number to be entered from the keyboard. Sample Input/output 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 Enter the number : 5 4 8 12 16 20 5 10 15 20 25