Thursday, 30 August 2018

Program in C to print digit pattern according to input number from user

(1.)  For printing this type structure in C:

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++)
    {
    printf ("%d", j) ;
    }
printf ("\n") ;
}
getch () ;
}

Output screen :: 

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
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++)
    {
    printf ("%d", i) ;
    }
printf ("\n") ;
}
getch () ;
}

Output screen :: 

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
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++)
    {
    number++;
    printf ("%d", number) ;
    }
printf ("\n") ;
}
getch () ;
}

Output screen :: 

Enter number of rows :: 5

output :

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15










1 comment:

  1. Great site, I will come back and review more information in future. Alan

    ReplyDelete

Featured post

Program to find maximum of three number using user define function in C++

A function can be define by the user as per the requirement of the user or programmer . To implement a user define function , a programmer ...