Print patterns using C Program

Pattern 1

#include<stdio.h>
#define pi 3.14
void main()
{
    int r;
    r=7;
    printf("Perimeter=%f",2*pi*r);
}

Output
Enter number of rows/columns: 5
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

Pattern 2

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

Output
*
**
***
****
*****

Pattern 3

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

Pattern 4

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

Output
*****
****
***
**
*

Pattern 5

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

Output
****
***
**
*

Leave a Reply

Your email address will not be published. Required fields are marked *