Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,260 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,551 people online right now. Registration is fast and FREE... Join Now!




Number Pyramid

 
Reply to this topicStart new topic

Number Pyramid

de_tutor
31 Oct, 2006 - 08:08 AM
Post #1

New D.I.C Head
*

Joined: 31 Oct, 2006
Posts: 6


My Contributions
[size=2]
Im using ANSI C. I've tried an output like pyramidal form:
for n=5
1
22
333
4444
55555
For this I've write the following program which gives the output:
for n=5
1
22
333
4444
55555
CODE
#include <stdio.h>
main()
{
int n,i,j;
clrscr();
printf("Enter a number:\n");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
printf("%d",i);
printf("\n");
}
getch();
}

Thank you.

edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Number Pyramid
31 Oct, 2006 - 08:14 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Did you have a question regarding this code, or were you simply posting for informational purposes?
User is offlineProfile CardPM
+Quote Post

Xing
RE: Number Pyramid
31 Oct, 2006 - 08:23 AM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
@de_tutor
Few points
1. Use code tags while posting code.
2. This site has code snippet and tutorial section. You can contribute there, of course after resolving some issues.
User is offlineProfile CardPM
+Quote Post

de_tutor
RE: Number Pyramid
3 Nov, 2006 - 06:53 AM
Post #4

New D.I.C Head
*

Joined: 31 Oct, 2006
Posts: 6


My Contributions
Yes, I've solved it.
CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,r,j;
clrscr();
printf("\n input the number");
scanf("%d",&n);
clrscr();
for(i=1;i<=n;i++)
{
      r=n-(i-1);
      for(j=1;j<=i;j++)
      {
            gotoxy(r+2*(j-1),i);
            printf("%d",i);

      }
}
getch();
}

Thanks.

edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

pearl579
RE: Number Pyramid
19 Sep, 2008 - 11:50 AM
Post #5

New D.I.C Head
*

Joined: 4 Aug, 2008
Posts: 7

Thanx for the help...even i was looking for this solution
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 06:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month