| | |
For Loop....Need Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 9
Reputation:
Solved Threads: 0
I am trying to implement these patters using for loop....I am having difficulties with them....If someone can help, would be great!!
I attached the pattern to a Image....

I tries this code for the third pattern...I have no Idea how to get them done....can anyone post codes for all of them?
I attached the pattern to a Image....
I tries this code for the third pattern...I have no Idea how to get them done....can anyone post codes for all of them?
int n=1,y=1,i=1,x=5;
for (i=1;i<=5;i++)
{ cout<<setw(x);
for(n=1;n<=y;n++)
{
cout<<"5";
}
cout<<endl;
y++;
x--;
} Last edited by dirnthelord; May 20th, 2009 at 1:17 pm.
•
•
•
•
I tries this code for the third pattern...I have no Idea how to get them done....can anyone post codes for all of them?
... Last edited by amrith92; May 20th, 2009 at 1:35 pm.
"C++ : Where friends have access to your private members."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
C++: You accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."
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!
this is just for learning,try to make your own codes!
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!
c++ Syntax (Toggle Plain Text)
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!
Somebody Rip My Heart Out, And Leave Me Here To Bleed!
•
•
Join Date: Jan 2009
Posts: 9
Reputation:
Solved Threads: 0
•
•
•
•
i am going to tell the first one only,you can try the rest by yourself.
c++ Syntax (Toggle Plain Text)
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!
c++ Syntax (Toggle Plain Text)
int c=1,a=5,d=1; for(int i=1;i<=5;i++) { for(int x=5;x>=i;x--) { cout<<c; if(c>=a) { cout<<setw(d); for(int y=5;y>=x;y--) { cout<<c; c--; } } c++; } c=1; a--; d+=2; cout<<endl; }
what should I do?
Last edited by dirnthelord; May 21st, 2009 at 11:52 am.
![]() |
Similar Threads
- Help with gui loop. (C)
- Loop...without the loop (Java)
Other Threads in the C++ Forum
- Previous Thread: help with loop
- Next Thread: I got stuck on loading the matrix from file
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






