I found this puzzle in some book and i dont know the solution. please tell me how to write this program.
The following pyramid should be printed using WHILE LOOP.
http://img813.imageshack.us/img813/9789/36177637.jpg
I found this puzzle in some book and i dont know the solution. please tell me how to write this program.
The following pyramid should be printed using WHILE LOOP.
http://img813.imageshack.us/img813/9789/36177637.jpg
First, you'll need to figure out how to describe the shape mathematically. Try coming up with a formula relating the line number to the number of stars on that line.
Then it's just a matter of putting that formula into the while loop, which will be a breeze.
I am sure the answer cant be this complicated, if anyone has a better code please reply...Code:#include <stdio.h> void main() { int i,j,k,l; i=4; l=1; while(i>=0) { j=i; while(j>0) { printf(" "); j--; } k=l; while(k>0) { printf("*"); k--; } l=l+2; i--; printf("\n"); } }
That is C. This is the C++ board. Which are you looking for?
I am sorry for posing in wrong board, i am just looking for correct algorithm
Goodness me, that’s way too complicated, lol.
It can be done with 3 integers.
is there any chance of reducing number of while loops
Yes, with two, if you’re happy to use a simple if else statement.