Asterisks Programming in C TYPE- 4

Posted on:
tags: , ,

/*This is a 'C'program which print the following
Asterisk pattern as output:- 
**********
 ****  ****
  ***    ***
  **      **
    *        * & so on*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int i,j,n,k; //variables
clrscr();
printf("Enter the number of lines upto which the pattern will print[natural number only]:");
scanf("%d",&n);
for(i=n;i>=1;i--)//start of loop.This loop control the row of pattern print.
{
for(j=1;j<=i;j++)//nested loop.This loop print the left side asterisk of pattern.
printf("*");
for(k=1;k<=2*(n-i);k++)//nested loop.This loop control the space between asterisk pattern.
printf(" ");
for(j=1;j<=i;j++)//nested loop.This loop print the right side asterisk of pattern.
printf("*");
printf("\n");//This statement is use to change row of the pattern.
}//end of loop
getch();
}//end of program

No comments:

Post a Comment

< >