#1 Butterfly Pattern Printing
Input : 5
Output:
Program For Butterfly Pattern Printing:
#include <stdio.h>
int main()
{
int i, j, n;
printf("Enter Number: ");
scanf("%d", &n);
// upper half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i >= j) // upper left triangle
printf("*");
else
printf(" ");
if(i >= (2 * n - 1) - j) // upper right triangle
printf("*");
else
printf(" ");
}
printf("\n");
}
// bottom half of the pattern
for(i = 0; i < n; i++)
{
for(j = 0; j < (2 * n); j++)
{
if(i + j <= n - 1) // bottom left triangle
printf("*");
else
printf(" ");
if((i + n) <= j) // bottom right triangle
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
0 Response to "Butterfly Pattern Printing"
Post a Comment