(1.) For printing this type structure in C:
1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Here as we seen the figure is in row and column form thus we have to declare two variable ( i and j ) for row and column respectively. Here we use for loop statement of c.
/* program to print structure */
#include<stdio.h>
void main()
{
int i,j,n ;
clrscr () ;
printf ("\n Enter number of rows:") ;
scanf ("%d", &n) ;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
for (j=1;j<=i;j++)
{
printf ("%d", j) ;
}
printf ("\n") ;
}
getch () ;
}
}
getch () ;
}
Output screen ::
Enter number of rows :: 5
output ::
Enter number of rows :: 5
output ::
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
(2.) For printing this type structure in C:
1
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Here as we seen the figure is in row and column form thus we have to declare two variable ( i and j ) for row and column respectively. Here we use for loop statement of c.
/* program to print structure */
#include<stdio.h>
void main()
{
int i,j,n ;
clrscr () ;
printf ("\n Enter number of rows:") ;
scanf ("%d", &n) ;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
for (j=1;j<=i;j++)
{
printf ("%d", i) ;
}
printf ("\n") ;
}
getch () ;
}
}
getch () ;
}
Output screen ::
Enter number of rows :: 5
output ::
Enter number of rows :: 5
output ::
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
(3.) For printing this type structure in C:
1
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Here as we seen the figure is in row and column form thus we have to declare two variable ( i and j ) for row and column respectively. Here we use for loop statement of c.
/* program to print structure */
#include<stdio.h>
void main()
{
int i,j,n,number=0;
clrscr () ;
printf ("\n Enter number of rows:") ;
scanf ("%d", &n) ;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
for (j=1;j<=i;j++)
{
number++;
printf ("%d", number) ;
}
printf ("\n") ;
}
getch () ;
}
}
getch () ;
}
Output screen ::
Enter number of rows :: 5
output :
Enter number of rows :: 5
output :
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Great site, I will come back and review more information in future. Alan
ReplyDelete