C program to print a pattern - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Wednesday, December 11, 2019

C program to print a pattern - My CS Tutorial

In this tutorial we will learn how to write a c program that print a pattern as:-

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


C program code


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
    int a,b,k,rows,count,temp;
    printf("\n Enter number of rows:\n ");
    scanf("%d",&rows);

  printf("\n");
  
    for(a=1;a<=rows;a++)
    {
        for(b=1;b<=a;b++)
        {
            printf(" * ");

        }

        printf("\n");
    }
 for(a=rows-1;a>=1;a--)
 {
  for(b=a;b>=1;b--)
  {
   printf(" * ");
  }
  printf("\n");
 }
 getch();
}


OUTPUT:




You can see the pattern of this program. We will enter a number of lines and then recieve a pattern.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.

Created by-- HARSH CHAUHAN



No comments:

Post a Comment