Welcome to Dream.In.Code
Getting C++ Help is Easy!

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




create a pyramid of numbers

 
Reply to this topicStart new topic

create a pyramid of numbers

karlsimmons
5 Mar, 2008 - 02:42 PM
Post #1

New D.I.C Head
*

Joined: 28 Feb, 2008
Posts: 5

I need to create a program that will create a pyramid of numbers (see attached file) in c++

What's the best way to do it? I know it has something to do with for-loops. Should I use nested for loops?

Any help is greatly appreciated.

This post has been edited by karlsimmons: 5 Mar, 2008 - 04:59 PM


Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

Stepler
RE: Create A Pyramid Of Numbers
5 Mar, 2008 - 04:28 PM
Post #2

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 27



Thanked: 2 times
My Contributions
CODE

#include<stdio.h>
#include<conio.h>
void main(void)
{
  clrscr();
  printf("Enter an integer\n");
  int n,n1=1;
  scanf("%d",&n);
  clrscr();
  for(short i=0;i<n;i+=1)
   {
    for(short j=0;j<=i;j+=1)
     {
      gotoxy(2*(i+1),(n-j));
      printf("%d",n-i);
      gotoxy(2*(2*n-i-1),(n-j));
      printf("%d",n-i);
     }
   }
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:37PM

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