Number Patterns | C - program

Print Patterns Using Number:


Tips:

1.Use nested loop.
for(......)
     for(........)

Patten 1:

1
12
123
1234
12345
..........
..............

Code:


#include<stdio.h>

void main()

{

    int stair,i,j;

    printf("Enter the pattern:\n");

    scanf("%d",&stair);

    for(i=0;i<=stair;i++)

    {

        for(j=1;j<=i;j++)

        {

            printf("%d",j);

        }

        printf("\n");

    }


}

Pattern 2:

..............
...........
54321
4321
321
21
1

Code:


#include<stdio.h>

void main()

{

    int stair,i,j;

    printf("Enter the pattern:\n");

    scanf("%d",&stair);

    for(i=stair;i>=0;i--)

    {

        for(j=i;j>=1;j--)

        {

            printf("%d",j);

        }

        printf("\n");

    }


}

Pattern 3:

1
2 3
4 5 6
7 8 9 10
.................
.....................

Code:


#include<stdio.h>

void main()

{

    int stair,i,j,c=1;

    printf("Enter the number of stair:\n");

    scanf("%d",&stair);

    for(i=0;i<=stair;i++)

    {

        for(j=0;j<=i;j++)

        {

            printf("%d\t",c++);

        }

        printf("\n");

    }

}

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :