
- Forum
- Programming Talk
- C and C++
- how to write a pyramid program?
how to write a pyramid program?
This is a discussion on how to write a pyramid program? within the C and C++ forums, part of the Programming Talk category; How 2 write a pgrm 4 the output below 1 2 3 4 5 6 7 8 9 10 thanks ...
-
06-09-2007, 01:36 AM #1
- Join Date
- Jun 2007
- Answers
- 4
how to write a pyramid program?
How 2 write a pgrm 4 the output below
1
2 3
4 5 6
7 8 9 10
thanks in advance
-
10-30-2009, 07:23 AM #2
- Join Date
- Oct 2009
- Location
- Bangalore, India
- Answers
- 2
Dummy Solution
Try to optimize the code
#include<stdio.h>
void main()
{
int i,j,k = 5, l=1;
for(i = 0; i <=3 ; i++)
{
for(j = 0; j <=10 ; j++)
{
if ((i == 0) && (j == 0))
{
printf("%d", l);
l++;
break;
}
if (i != j)
{
printf("%d ", l);
l++;
}
if(i == j)
{
printf("%d ", l);
l++;
break;
}
}
printf("\n");
}
}
-
Hey, try it out
public void run() {
int base = 14;
for (int i = 0; i < base; i++)
{
for (int j = 1; j < BRICK_HEIGHT; j++)
{
int x = BRICK_WIDTH * i;
int y = getHeight() - (BRICK_HEIGHT * j);
GRect brick = new GRect(x, y, BRICK_WIDTH, BRICK_HEIGHT);
add(brick);
}
}
}
-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
printf("enter the no of row --");
scanf("%d",&i);
for(j=0;j<=i-1;j++)
{
for(k=0;k<=j;k++)
{
printf("*");
}
printf("\n");
}
getch();
}
O/P
enter the no of row --5
*
**
***
****
*****
try this out
-
08-18-2010, 02:41 AM #5
- Join Date
- Aug 2010
- Answers
- 1
int main()
{
int n ,i,j,t=0;
///////// read n
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
printf("%d",t);
t++;
}
}
}
-
09-23-2010, 09:24 AM #6
- Join Date
- Sep 2010
- Answers
- 2
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int i,j,n=1;
for(i=1;i<=4;i++){
for(j=1;j<=i;j++){
printf("%d",n);
n++;
printf("");
}
printf("\n");
}
getch();
}
Last edited by admin; 09-23-2010 at 09:30 AM.
-
Sponsored Ads

Reply With Quote





