Tuesday, 21 July 2015

Pattern 10

Write a C program to print the following pattern:



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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<i;j++)
        {
            printf(" ");
        }
        for(k=i;k<=n;k++)
        {
            printf(" *");
        }
        printf("\n");
    }
}

 
 
OUTPUT:
 
 
 

Pattern 9

Write a C program to print the following pattern:



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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=i;j<n;j++)
        {
            printf(" ");
        }
        for(k=1;k<=i;k++)
        {
            printf(" *");
        }
        printf("\n");
    }
}
 
 
OUTPUT:
 
 
 
 

Pattern 8

Write a C program to print the following pattern:



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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<i;j++)
        {
            printf(" ");
        }
        for(k=i;k<=n;k++)
        {
            printf("*");
        }
        printf("\n");
    }
}

 
 
OUTPUT:
 
 
 
 

Pattern 7

Write a C program to print the following pattern:

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

 

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=i;j<n;j++)
        {
            printf(" ");
        }
        for(k=1;k<=i;k++)
        {
            printf("*");
        }
        printf("\n");
    }
}

 
 
OUTPUT:
 
 
 

Pattern 6

Write a C program to print the following pattern:



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

CODE:

#include<stdio.h>
void main()
{
    int i,j,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=n;j>=i;j--)
        {
            printf("*");
        }
        printf("\n");
    }
}

 
 
OUTPUT:
 


Pattern 5

Write a C program to print the following pattern:



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

CODE:

#include<stdio.h>
void main()
{
    int i,j,n;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("*");
        }
        printf("\n");
    }
}

 
 
OUTPUT:
 
 
 

Sunday, 19 July 2015

Pattern 4

Write a C program to print the following pattern:


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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the no of rows \n");
    scanf("%d",&n);
    for(i=1;i<=n/2;i++)
    {
        for(j=n/2;j>i;j--)
        {
            printf(" ");
        }
        for(k=1;k<=i*2-1;k++)
        {
            printf("*");
        }
        printf("\n");
    }
    for(i=n;i>n/2+1;i--)
    {
        for(j=n;j>=i;j--)
        {
            printf(" ");
        }
        for(k=n+2;k<i*2-1;k++)
        {
            printf("*");
        }
        printf("\n");
    }
}
 
 
OUTPUT:
 
 
 

Pattern 3

Write a C program to print the following pattern:

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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n,l,m;
    printf("Enter the number of rows: \n");
    scanf("%d",&n);
    for(i=1;i<=n/2;i++)
    {
            for(j=i;j<=n/2;j++)
            {
                    printf("*");
            }
            for(k=1;k<i;k++)
            {
                    printf("  ");
            }
            for(j=i;j<=n/2;j++)
            {
                    printf("*");
            }
            printf("\n");
    }
    for(i=n/2+1;i<n;i++)
    {
            for(l=i+1;l>n/2;l--)
            {
                printf("*");
            }
            for(m=i+1;m<n;m++)
            {
                printf("  ");
            }
            for(l=i+1;l>n/2;l--)
            {
                printf("*");
            }
            printf("\n");
    }
}
 
 
OUTPUT:
 
 
 

Pattern 2

Write a C program to print the following pattern:

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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the number of rows :\n");
    scanf("%d",&n);
    for(i=n;i>=1;i--)
    {
        for(k=n;k>i;k--)
        {
            printf(" ");
        }
        for(j=i*2-1;j>=1;j--)
        {
            printf("*");
        }
        printf("\n");
    }
}
 
 
OUTPUT:
 
 
 

Pattern 1

Write a C program to print the following pattern:

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

CODE:

#include<stdio.h>
void main()
{
    int i,j,k,n;
    printf("Enter the no of rows \n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        for(j=n;j>i;j--)
        {
            printf(" ");
        }
        for(k=1;k<=i*2-1;k++)
        {
            printf("*");
        }
        printf("\n");
    }
}

OUTPUT: