Nov 11, 2012 at 11:38am
hello, I'm trying to figure out loops and so far, I think I'm being very inefficient.
I'm trying to output this.
5 7 9 11 10 8 6 4
3 6 9 8 5 2
2 6 5 1
|
This is the code I have, but looks terrible to me. Any help or guidance would be appreciated, thank you for your time.
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
|
#include <iostream>
using namespace std;
int main()
{
int i =5;
while (i!=13)
{
cout<<i<<" ";
i+=2;
}
i=10;
while(i!=2)
{
cout <<i<<" ";
i-=2;
}
cout<<endl;
i=3;
while(i!=12)
{
cout<<i<<" ";
i+=3;
}
i=8;
while(i!=-1)
{
cout<<i<<" ";
i-=3;
}
cout<<endl;
i=2;
while(i!=10)
{
cout<<i<<" ";
i+=4;
}
i=5;
while(i!=-3)
{
cout<<i<<" ";
i-=4;
}
cout<<endl;
system("pause");
return 0;
}
|
Last edited on Nov 11, 2012 at 11:39am