Trial and error I reckon and nested for loops.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Sure, just post the code for one of them you're having trouble with.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
i am going to tell the first one only,you can try the rest by yourself.
think of first figure as four triangles!
1.thats counts and prints in ascending order
2.thats counts and prints in descending order
3.one that prints spaces " " in ascending order
4.this one also prints spaces " " in ascending order
first of all determine the number of rows you want to print.
here we have 5
so this means we will have to make an outer loop that runs 5 times
,then come the nested loops!....
then all you have to do is,check all the conditions.do some dry runs on your copy first.this way you will understand!
you wont be able to do this unless you try it yourslef!
just practice practice and practice!
here is the code,i had a similar assignment ,way back.changed it a bit.but it prints "5" twice,you figure it out yourself!
for(int x=5;x>0;x--)
{
for(int b=0;b<x;b++)
{
cout << b+1;
}
for(int c=5;c>x;c--)
{
cout << " ";
}
for(int e=4;e>x;e--)
{
cout << " ";
}
for(int d=x;d>0;d--)
{
cout << d;
}
cout << endl;
}
this is just for learning,try to make your own codes!
arshad115
Junior Poster in Training
65 posts since Nov 2008
Reputation Points: 7
Solved Threads: 2
thats good,just keep on trying!
you will get the results!
arshad115
Junior Poster in Training
65 posts since Nov 2008
Reputation Points: 7
Solved Threads: 2