Asterisks Programming in C TYPE- 2

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=1;i<=n;i++)//start of loop.This loop control the row of pattern print.
{
for(k=1;k<=n-i;k++)//nested loop.This loop control the space of pattern.
printf(" ");
for(j=1;j<=i;j++)//nested loop.This loop print the 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

< >