Pyramid in C++


by Naldo6
Tags: pyramid
Naldo6
Naldo6 is offline
#1
Oct25-08, 06:44 PM
P: 103
I need to do a pyramid in C++ like this one:
*
* *
* * *
* * * *
* * * * *

buti just know how to do the figure at one side:

*
* *
* * *
* * * *
* * * * *


# include <stdio.h>
# include <math.h>

void main()
{

int count,count2;

for(count=1;count<=5;count++)
{
for(count2=1;count2<=count;count2++)
printf(" *");
printf("\n");
}
}

Can anyone help me hoy to change from the side to a pyramid form?
Phys.Org News Partner Science news on Phys.org
Scientists pinpoint when harmless bacteria became flesh-eating monsters
Asian air pollution affect Pacific Ocean storms
Rocket leak delays space station delivery launch (Update)
Borek
Borek is offline
#2
Oct25-08, 07:08 PM
Admin
Borek's Avatar
P: 22,650
Please elaborate, as both pyramids look identical.
Naldo6
Naldo6 is offline
#3
Oct25-08, 07:14 PM
P: 103
ok sorry, i did it as a pyramid but the page puts it at the corner yet. Bu i mean i just know how to do the figure that is above drawn with the *, but i ned to do it but in the pyramid form, like a triangle of the cue ball, but with base 5.

Borek
Borek is offline
#4
Oct25-08, 07:18 PM
Admin
Borek's Avatar
P: 22,650

Pyramid in C++


You have to print spaces before stars.
Naldo6
Naldo6 is offline
#5
Oct25-08, 07:19 PM
P: 103
ok, and howi do that?....
Naldo6
Naldo6 is offline
#6
Oct25-08, 07:21 PM
P: 103
how i do that in my code above ?
mathmate
mathmate is offline
#7
Oct25-08, 08:20 PM
P: 366
If you draw your triangle with visible spaces, then you can count how many you need on each line, and you can programme accordingly, right?

----*
---*-*
--*-*-*
-*-*-*-*
*-*-*-*-*
So you see that there are fours spaces on the first line, three on the second, and so on.
Now you just have to translate that into your code.
Naldo6
Naldo6 is offline
#8
Oct25-08, 08:35 PM
P: 103
ok, i know that ther i need always four spaces in each line but i dont know how to put that in codes for run my programs perfectly....i just know how to put all the * to begin at the left corner....that the problem

can u help me more?....
mathmate
mathmate is offline
#9
Oct25-08, 08:53 PM
P: 366
.....
for(count=1;count<=5;count++)
{
/* here you need to insert 4 spaces when count==1,
3 spaces when count==2, (3=5-2)
2 spaces when count==3, (2=5-3)
1 space when count==4, (1=5-4)
0 space when count==5 (0=5-5)
get the idea?
You can do this with an additional for/next loop that runs 5-count times, each time it should print ONE space.
Try it out, if it does not work, post this part of your code.
If it works, post the result!!
*/
for(count2=1;count2<=count;count2++)
printf(" *");
printf("\n");
}
.....
Naldo6
Naldo6 is offline
#10
Oct25-08, 09:08 PM
P: 103
Do you mean that right?...

but i dont know how to state the instruction of teh spaces in that for between the other two for...
help me a little more plz

# include <stdio.h>
# include <math.h>

void main()
{

int count,count2;

for(count=1;count<=5;count++)
{
for( ; ; )
for(count2=1;count2<=count;count2++)
printf(" *");
printf("\n");

}
}
Naldo6
Naldo6 is offline
#11
Oct25-08, 09:16 PM
P: 103
i dont know how to do this:

You can do this with an additional for/next loop that runs 5-count times, each time it should print ONE space.

i have just discuss in my class the instruction for no more than that....
mathmate
mathmate is offline
#12
Oct25-08, 09:28 PM
P: 366
for(count=1;count<=5;count++)
{
// complete the start value and end condition for the loop, the index should increment by one
for( ; ; ){ /* here you add a printf statement that prints simply " " (a space)*/}
//
for(count2=1;count2<=count;count2++)
printf(" *");
printf("\n");

}
Naldo6
Naldo6 is offline
#13
Oct25-08, 09:34 PM
P: 103
ty... i sucees with my pyramid i get the correct code

# include <stdio.h>
# include <math.h>

void main()
{

int count,count2,count1;


for(count=1;count<=5;count++)
{
for(count1=count;count1<=5;count1++)
printf(" ");
for(count2=1;count2<=count;count2++)
printf(" *");
printf("\n");

}
}
mathmate
mathmate is offline
#14
Oct25-08, 09:39 PM
P: 366
Congratulations!!!
Naldo6
Naldo6 is offline
#15
Oct25-08, 09:59 PM
P: 103
ty..... i will need your help durng the rest of the semester... i have another homeworks.. i will begin on the week so i will request your help... a lot of thanks...


Register to reply

Related Discussions
::::square pyramid::::: Calculus & Beyond Homework 8
Pyramid Game Precalculus Mathematics Homework 2
square pyramid? General Math 4
Pyramid of Egypt Brain Teasers 12