Pattern Program in C Programming Language (post - 1)

Rumman Ansari   2018-05-10   Student   C Programming Language > Pattern Programming   2801 Share

In this blog you will get * Pattern Programs. For chapterwise program list click here

This blog is our first blog for Pattern Programs. If you want to know more about * Pattern Programs also read from below link.

Read out second post about parttern programming

Program1:


#include<stdio.h>
void main()
{
    int i, j ;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=5 ; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * * 

Program2:


/**
 * C program to print square star pattern
 */

#include<stdio.h>

int main()
{
    int i, j, N;

    // Input number of rows from user
    printf("Enter number of rows: ");
    scanf("%d", &N);

    // Iterate over rows
    for(i=1; i<=N; i++)
    {
        // Iterate over columns
        for(j=1; j<=N; j++)
        {
            // Print star for each column
            printf("*");
        }
        
        // Move to the next line/row
        printf("\n");
    }

    return 0;
}

Output:

Enter number of rows: 6
******
******
******
******
******
****** 

Program3:


#include<stdio.h>
void main()
{
    int i, j ;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=5 ; j++)
        {
            printf("%d ", i);
        }
        printf("\n");
    }
}

Output:

1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5 

Program4:


#include<stdio.h>
void main()
{
    int i, j ;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=5 ; j++)
        {
            printf("%d ",j);
        }
        printf("\n");
    }
}

Output:

1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5 

Program5:


#include<stdio.h>
void main()
{
    int i;
    for(i=1 ; i<=25 ; i++)
    {
        printf("* ");
        if(i%5==0)
            printf("\n");
    }
}

Output:

* * * * *
* * * * *
* * * * *
* * * * *
* * * * * 

Program6:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=i ; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
}

Output:

*
* *
* * *
* * * *
* * * * * 

Program7:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=i ; j++)
        {
            printf("%d ", i);
        }
        printf("\n");
    }
}

Output:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5 

Program8:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=1 ; j<=i ; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5 

Program9:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=5 ; i>=1 ; i--)
    {
        for(j=5 ; j>=i ; j--)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

5
5 4
5 4 3
5 4 3 2
5 4 3 2 1 

Program10:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=5 ; i>=1 ; i--)
    {
        for(j=i ; j<=5 ; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

5
4 5
3 4 5
2 3 4 5
1 2 3 4 5 

Program11:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=i ; j>=1 ; j--)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

1
2 1
3 2 1
4 3 2 1
5 4 3 2 1 

Program12:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=i ; j<=5 ; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

1 2 3 4 5
2 3 4 5
3 4 5
4 5
5 

Program13:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=1 ; i<=5 ; i++)
    {
        for(j=5 ; j>=i ; j--)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5 

Program14:


#include<stdio.h>
void main()
{
    int i, j;
    for(i=5 ; i>=1 ; i--)
    {
        for(j=i ; j>=1 ; j--)
        {
            printf("%d ", j);
        }
        printf("\n");
    }
}

Output:

5 4 3 2 1
4 3 2 1
3 2 1
2 1
1 
Read out second post about parttern programming