QUESTION:- print the following pattern
*
* * *
* * * * *
* * *
*
program
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j, k, no, sp, a;
char sym;
printf("enter a symbol to print a pattern: ");
scanf("%c", &sym);
printf("Enter a value: ");
scanf("%d", &no);
if (no % 2 == 0)
{
no++;
/*
2%2 = 0
0+1 = -1
*/
printf("due to insufficient number that u input, we have increase a digit and make it %d \n", no);
}
a = (no / 2) + 1;
/*
5/2=2
2+1=3
*/
for (i = 1; i <= a; i++)
{
for (j = a; j >= i; j--)
{
printf(" ");
}
for (k = 1; k <= (2 * i) - 1; k++)
/*
2*1-1 = 1
2*2-1 = 3
2*3-1 = 5
*/
{
printf("%c", sym);
}
printf("\n");
}
sp = 2;
for (i = (no / 2); i >= 0; i--)
{
for (j = 1; j <= sp; j++)
{
printf(" ");
}
sp++;
for (k = 1; k <= (2 * i) - 1; k++)
{
printf("%c", sym);
}
printf("\n");
}
return 0;
getch();
}
OUTPUT
enter a symbol to print a pattern: *
Enter a value: 5
*
***
*****
***
*
0 Comments