| | |
how to display this shape using for loop?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
0
#3 Nov 9th, 2009
Here is a hint :
So you see that they decrease by 1 star until they reach 1 then they
start increment.
so assuming you can separate this problem into 2 blocks, you can
do something like this :
Now what should your printStars look like :
for example if one calls printStars(4) it should output the following :
Go ahead and try to devise printStars then you problem becomes much
easier.
C++ Syntax (Toggle Plain Text)
********** 10 stars ********* 9 stars ******** 8 stars ******* 7 stars ****** 6 stars ***** 5 stars **** 4 stars *** 3 stars ** 2 stars * 1 stars ** 2 stars *** 3 stars **** ***** ****** ******* ******** ********* ********** 10 stars
So you see that they decrease by 1 star until they reach 1 then they
start increment.
so assuming you can separate this problem into 2 blocks, you can
do something like this :
C++ Syntax (Toggle Plain Text)
for(int i = 10; i != 1; i--) printStars(i); //a function that prints i stars with endl for(int i = 2; i <= 10; i++) printStars(i);
Now what should your printStars look like :
for example if one calls printStars(4) it should output the following :
C++ Syntax (Toggle Plain Text)
****
Go ahead and try to devise printStars then you problem becomes much
easier.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
This should do...
Please, if this satisfies your problem,mark this thread as solved.Thanks
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; void printstar(int num_of_times); void reverseprint(int highest); int main() { for(int i=0;i<10;i++){ printstar(i); } reverseprint(10); return 0; } void printstar(int num_of_times){ for(int i=0;i<num_of_times;i++){ cout<<"* "; } cout<<endl; } void reverseprint(int highest){ for(int i=0;i<highest;i++){ int x=highest-i; printstar(x); } cout<<endl; }
•
•
•
•
"Show me your code and i will tell you who you are.."---Tkud
![]() |
Similar Threads
- help with - Read csv into vector and display elements of vector. (C++)
- decimal to binary in while loop..stuck (C++)
- for loop question (C++)
- vb6/common dialog/access db (Visual Basic 4 / 5 / 6)
- Need help writing a program (C++)
- While and Do While Help (C++)
- Someone Be My Program Study Buddy (C++)
- Switch Case Statement (Java)
- for loops (C)
Other Threads in the C++ Forum
- Previous Thread: String Calculator C++
- Next Thread: PLEASE HELP! very difficult Homework
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






