Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j,x=30,y=10;
clrscr();
printf("Enter n (between 2 & 9) : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
gotoxy(x,y);
for(j=1;j<=i;j++)
printf("%d ",i);
x=x-1;
y++;
}
getch();
}
Output :
Enter n (between 2 & 9) : 9 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9
Explain ?
gotoxy(x,y);
- Gotoxy : interpret it as “goto x y”
- Moves Cursor Position to Co-Ordinate (x,y)
- gotoxy(10,40) : moves Cursor Position to Co-ordinate (10,40)
x=x-1;
y++;
- In Each Iteration we are moving downward so increment “y”
- For each new Iteration we are starting from beginning but one co-ordinate back so decrement x
for(j=1;j<=i;j++)
printf("%d ",i);
- Nested Loop Used to Print All the Numbers in Particular Line . i.e in the third line i = 3 so j will print values 3 times .







HOW TO PRINT THIS
0
1 1 1
2 2 2 2 2
3 3 3 3 3 3 3
AND SO ON TILL 9.
PLEASE TELL FAST I HAVE TO SUBMITT MY ASSIGNMENT
THANKS
void main()
{
int i,j;
clrscr();
for(i=0;i<=9;i++)
{
for( j=0 ; j<(1+2*i) ; j++ )
printf("%d ",i);
printf("n");
}
getch();
}
Here In the first row i=0 and total number of elements printed = 1+2i = 1
Here In the Second row i=1 and total number of elements printed = 1+2i = 3
Here In the Second row i=2 and total number of elements printed = 1+2i = 5
…
..
..
..
..
..
So on
http://www.c4learn.com/2010/09/print-following-pattern-of-pyramid.html
i wanted to know how to write a nested loop to create a pyramid pattern and get output. pls its urgent
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
void main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%dt",j);
}
printf("n");
}
getch();
}
I wanted to know how to print a output if the input is given as
2,4,3,6,1
Output:
*
*
* *
***
****
*****
and input is been changed.
@Ansh If u r able to elaborate Problem Statement then it would be easy to answer
how to print
***
##
$
1
12
123
1234
12345