Jump to content

Print pyramid number?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts
Anyone know how to make this...
____1
___1 2
__1 2 3

Or this...

____1
___2 2
__3 3 3

without the underscore..

thanks.

#2
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
I do, but show us your code first and we'll help you. We don't just do your homework here.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#3
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
this is for the 1st one , just play with the settings , 2nd one is same as the 1st you need little changing ;)

for(int i=1;i<=3;i++){

   for(int j=1;j<=i;j++){ 

    cout<<j<<" "; }

     cout<<endl; }


#4
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts

Aereshaa said:

I do, but show us your code first and we'll help you. We don't just do your homework here.

haha...
this is not home work...

@ahmed
sorry, im using C not C++

#5
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts
its print * how to change it with number as i said above...


#include <stdio.h>

#include <conio.h>


int main()

{

   int n,

   i,j;

   printf("Input : ");

   scanf("%d",&n);

   for (i=0;i<n;i++)

   {

       for (j=0;j < n - i;j++)

           printf(" ");

       for (j=0;j<2 * i + 1 ;j++)

           printf("*");

       printf("\n");

   }

   getch();

   return 0;

}




#6
nitediver

nitediver

    Newbie

  • Members
  • PipPip
  • 14 posts
its bit closer, but the output is...

-----1
---2 2
-3 3 3

what i want is...
---1
--2 2
-3 3 3

OR

---1
--1 2
-1 2 3

#include<conio.h>
void main()
{
int i,n,j,x=40,y=10;
clrscr();
printf("Enter n (between 2 & 9)\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
gotoxy(x,y); /* To take the cursor to the co-ordinates x & y */
for(j=1;j<=i;j++)
{
 printf("%d",i);
}
x=x-1;
y++;
}
getch();
}


#7
HumbleMumbleWump

HumbleMumbleWump

    Newbie

  • Members
  • Pip
  • 6 posts
I would use an outer loop to keep track of the number of preceding spaces to print (also decrement instead of increment the counter you use for this loop since the number of preceding spaces decreases). The inner loop should be pretty straightforward depending on which outcome you want.