How do you create a Triangle Pattern using for loops?
#include<stdio.h>
#include<conio.h>
void main ()
{
int pas,i,j,k;
clrscr();
printf("\n\n\tEnter the size of pascal triangle (upto 99) : ");
scanf("%d",&pas);
printf("\n\n\n");
for(i=1;i<=pas;i++)
{
for(j=pas;j>i;j--)
{
printf(" "); }
for(k=1;k<=i;k++)
{
printf("%2d",i);
// printf(" *",i); /* to print the pattern with asterisk
uncomment it and comment the above
statement */
// printf(" *",i); /* to print the pattern with asterisk
uncomment it and comment the above
statement */
}
printf("\n");
}
printf("\n\n\n\t Pascal Triangle %d",pas);
getch ();
}
No comments:
Post a Comment