Social Icons

Friday, 21 March 2014

C pattern program of stars and alphabets

Creating a pattern involves how to use nested loops properly, some pattern may involve alphabets or other special characters.

#include <stdio.h>
#include<conio.h>
main()
{
int n, c, k, space, count = 1;
clrscr();
printf("\n Enter number of rows : ");
scanf("%d",&n);
space = n;
for ( c = 1 ; c <= n ; c++)
{
printf("\n\t");
for( k = 1 ; k < space ; k++)
printf(" ");
for ( k = 1 ; k <= c ; k++)
{
printf("*");
if ( c > 1 && count < c)
{
printf("D");
count++;
}
}
space--;
count = 1;
}
getch();
}

also see codes of following-
Floyd triangle
Pascal triangle


                                                          OUTPUT

 

No comments:

Post a Comment