![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2004
Posts: 31
Rep Power: 0
![]() |
i am having a problem in doing the above problem.. i tried myself but still cannot get the answer ..here i will post the output a s well as the code i written...tell me where have i gone wrong...
* *** ***** ******* ***** *** * code #include<iostream.h>
int main()
{
int z;
for(int i=0;i<5;i++)
{
for(int j=0;j<2*i+1;j++)
{
cout<<"*";
}
if(i==3 && j>2*i){
for(int z=i;z<i;z--)
{
cout<<" ";
}
}
cout<<"\n";
}
return 0;
} |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2004
Posts: 18
Rep Power: 0
![]() |
exactly what should this code be doing?
i'm guessing you want to print a triangle of asterisks right? |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Please put your code in [code] tags - I can't even read that. And indent it as well, if you wouldn't mind.
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2004
Posts: 31
Rep Power: 0
![]() |
yeah ..... i tried to do it but cannot... i can only think of that part i ve post... can you me to complete the program...
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I would do it like this:
for (int i = 1; i <= numlines; i++) {
for (int j = 1; j <= (i * 2 - 1); j++) {
cout << "*";
}
cout << endl;
}Piece of piss. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Oct 2004
Posts: 31
Rep Power: 0
![]() |
your code is wrong... I want to print
* *** **** ***** **** *** * please post the code... |
|
|
|
|
|
#7 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
You're going to have to input the number of lines you want it to print.
#include <stdio.h>
int main(void)
{
int numlines;
scanf("%d", &numlines);
for (int i = 0; i<numlines; i++)
{
if(i<=numlines/2)
{
for (int j = 0; j < (i * 2 + 1); j++)
{
printf("*");
}
}
else
{
for(int j = 0; j<((numlines-i)*2-1); j++)
{
printf("*");
}
}
printf("\n");
}
return 0;
}
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Oct 2004
Posts: 31
Rep Power: 0
![]() |
thanks for the information.....now i have figured out how to do such problems.....thanks
|
|
|
|
|
|
#9 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
My code printed:
* *** ***** ******* ***** *** * which is what you asked for. Scroll up. |
|
|
|
|
|
#10 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Hmm. For me, Ooble, your code printed:
* ** *** **** ***** I believe. Maybe I did something wrong.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|