Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 7th, 2004, 1:11 AM   #1
kalinga1234
Programmer
 
Join Date: Oct 2004
Posts: 31
Rep Power: 0 kalinga1234 is on a distinguished road
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;
}
kalinga1234 is offline   Reply With Quote
Old Nov 7th, 2004, 7:03 AM   #2
BruceLeroy
Newbie
 
Join Date: Nov 2004
Posts: 18
Rep Power: 0 BruceLeroy is on a distinguished road
exactly what should this code be doing?

i'm guessing you want to print a triangle of asterisks right?
BruceLeroy is offline   Reply With Quote
Old Nov 7th, 2004, 10:17 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Please put your code in [code] tags - I can't even read that. And indent it as well, if you wouldn't mind.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 7th, 2004, 7:27 PM   #4
kalinga1234
Programmer
 
Join Date: Oct 2004
Posts: 31
Rep Power: 0 kalinga1234 is on a distinguished road
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...
kalinga1234 is offline   Reply With Quote
Old Nov 7th, 2004, 8:04 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 7th, 2004, 10:04 PM   #6
kalinga1234
Programmer
 
Join Date: Oct 2004
Posts: 31
Rep Power: 0 kalinga1234 is on a distinguished road
your code is wrong... I want to print


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

please post the code...
kalinga1234 is offline   Reply With Quote
Old Nov 7th, 2004, 10:17 PM   #7
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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;

  
}
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Nov 8th, 2004, 2:59 AM   #8
kalinga1234
Programmer
 
Join Date: Oct 2004
Posts: 31
Rep Power: 0 kalinga1234 is on a distinguished road
thanks for the information.....now i have figured out how to do such problems.....thanks
kalinga1234 is offline   Reply With Quote
Old Nov 8th, 2004, 8:23 AM   #9
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
My code printed:

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

which is what you asked for. Scroll up.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Nov 8th, 2004, 3:57 PM   #10
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Hmm. For me, Ooble, your code printed:

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

I believe. Maybe I did something wrong.
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC