How to print this -
Question- Write a complete C program to print the following pattern for n number of rows, where n is supplied externally,
* *
** **
*** ***
**** ****
*********
#include<stdio.h>
#include<conio.h>
int main()
{
int n,star=0,space,width,i,j;
printf("ENTER LENGTH: ");
scanf("%d",&n);
n+=1;
width=(n*2)-4;
for(i=0;i<n;i++)
{
space=width-star*2;
for(j=0;j<width+1;j++)
{
if(j<star||j>(star+space))
printf("*");
else
printf(" ");
}
printf("\n");
star++;
}
}
Code is 100% working.
Compiled with GCC 4.6.1 with -std=c99 option enabled.
IDE = orwell Dev-C++ v5.2.0.3
No comments:
Post a Comment