/*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; //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 first loop(use for incresing of number of asterisk).This loop control the row of pattern print.
{
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 first loop
for(i=(n-1);i>=1;i--)//start of second loop(use for decresing of number of asterisk).This loop control the row of pattern print
{
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 second loop
getch();
}//end of program
No comments:
Post a Comment