You are on page 1of 5

Trace

for (int k = 1; k<30; k++)


if (k % 5 = = 0 || k % 7 = = 0)
cout<<setw(3)<< k+1;
cout<<endl;

Output
6 8 11 15 16 21 22 26 29
int nm;
const int one = 1; Output
const int two = 2;
const int three = 3;
1
for (int n = 1; n < 10; n++)
22
{
switch (n % three)
333
{
case 1:
1111
nm = one;
break;
22222
case 2: 333333
nm = two;
break; 1111111
default:
nm = three; 22222222
}
for (int m = 1; m <= n; m++) 333333333
cout << nm;
cout << endl;
}
Write a program segment
1 for(int i = 1; i <= 9; i++)
12 {
*** for(int j = 1; j <= i; j++)
1234 if(i % 3 == 0)
12345 cout << "*";
****** else
1234567 cout << j;
12345678 cout << endl;
********* }
Write a program segment
* for(int i = 1; i <= 9; i++)
* {
* for(int j = 1; j <= i; j++)
* if(j < i)
* cout << ' ';
* else
* cout << setw(2) << '*';
* cout << endl;
* }
Write a program segment
********** for(int i = 1; i <= 10; i++)
*********
********
******* { for(int j = 1; j <= 10-i+1; j++)
****** cout << setw(2) << '*';
*****
**** cout << endl;
*** }
**
*

You might also like