nested for loops
Dec 23, 2015 at 3:25pm UTC
Chaps I am stuck with a nested for loop exercise. Basically if you run my code I need to print mirror images of the 1st two. I have tried allsorts and I simply can not get it to work.
Is anyone able to give me some pointers...
Thanks in advance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
for ( int i = 1; i <= 10; i++)
{
for ( int j = 1; j <= i; j++ )
{
cout << "*" ;
}
cout << endl;
}
cout << endl;
for ( int i = 10; i >= 1; i--)
{
for ( int j = 1; j <= i; j++ )
{
cout << "*" ;
}
cout << endl;
}
cout << endl;
// for ( int i = 10; i >= 1; i--)
// {
// for ( int j = 1; j <= i; j++ )
// {
// for ( int k = 1; k < 10; k++ )
// {
// cout << "*";
// }
// cout << " ";
// }
// cout << endl;
// }
return 0;
}
Dec 23, 2015 at 3:26pm UTC
Sorry I forgot to mention the mirror images have to start with spaces... if you get what I mean!!
Topic archived. No new replies allowed.