Pages

Star Pattern Printing Programs in C (SET 2)

star pattern in C :: futureX

PROGRAM 1

   *
  * *
 * * *
* * * *

--------------------------------

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l;
printf("enter value of k");
scanf("%d",&k);

for(i=k;i>0;i--)
{
for(l=(i-1);l>0;l--)

{printf(" ");

}
for(j=i;j<=k;j++){
printf("*");
printf(" ");
}
printf("\n");

}
}



PROGRAM 2


    *
   * *
  *   *
 *     *
*       *

--------------------------------



#include<stdio.h>              
#include<conio.h>
void main()
{
int h,i,j,k;
clrscr();
printf("Enter the value");
scanf("%d",&k);
for(h=1;h<k;h++)
printf(" ");
printf("*\n");

for(i=0;i<(k-1);i++)
{for(j=i;j<(k-2);j++)
printf(" ");
printf("*");
for(j=0;j<(2*i+1);j++)
printf(" ");
printf("*\n");
}

getch();
}

No comments:

Post a Comment