Hi !!!!
I want to write a program that print the character # like a triangle in the middle of the page.I mean like this :

#
# # #
# # # # #
# # # # # # #
# # # # # # # # #
# # # # # # # # # # #
1,3,5,7,9 in the lines 1,2,3,4,5
Please Help me!!!
but i don't mean like that.i mean the characters must be like a equilateral.
Thanks a lot

Recommended Answers

All 4 Replies

Ok, so what have you tried so far? We don't give complete homework solutions here.
Hint, you're going to need 'nested loops'

ok thanks
I wrote this code and because of the gotoxy() he can't print in the middle of the page.The code is :

I wrote the code in visual C++ 2008 when I write it in Borland C++ it works correctly but i want it in Visual C++ 2008.

#include <iostream>
#include <conio.h>

using namespace std;

void main()
{
	for(int i = 0 ; i <= 4 ; i++)
	{
          gotoxy(20-i , 10+i);
          for(int j=1 ;  j <= 2*i+1 ; j++)
		 cout<<"#";  
		cout<<endl;
	}
	getch();
}

but the error is :

error C3861: 'gotoxy': identifier not found

conio.h isn't bundled with many compilers/IDEs. You can do what you want to do without it by thinking of the page as a grid of cells. The grid can be viewed as lines of cells, like a chess board. Each cell may hold 1 character. Some char may be visible and others, like the space char or the tab char or the new line char, may not. So if the line holds 20 char and you want to put a * in the middle, what char might precede that lonely * in the middle of the line? How many such char should there be to ensure the * is in the mddle of the line? Then you can extend the analysis to having two or three *s on the second line, etc.

Mate you dont need gotoxy(). Neither it is standard nor it is needed. I'll give you a hint which is already posted, use white space. It means to place required number of spaces (' ') before printing the characters :

______#
_____###
____#####
___#######
__#########

here the underscore should be actually spaces, but I have put them so that you know where the spaces shd come

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.