Anyone know how to make this...
____1
___1 2
__1 2 3
Or this...
____1
___2 2
__3 3 3
without the underscore..
thanks.
Print pyramid number?
Started by nitediver, Oct 16 2009 06:49 AM
6 replies to this topic
#1
Posted 16 October 2009 - 06:49 AM
|
|
|
#2
Posted 16 October 2009 - 07:15 AM
#3
Posted 16 October 2009 - 07:20 AM
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
Posted 16 October 2009 - 07:23 AM
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
Posted 16 October 2009 - 07:38 AM
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
Posted 16 October 2009 - 07:46 AM
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
-----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
Posted 17 October 2009 - 07:07 PM
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.


Sign In
Create Account


Back to top









