(6)
#include <stdio.h>
int main()
{
char prnt = '*';
int i, j, k, s, nos = -1;
for (i = 5; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{ if (i == 5 && k == 5)
{ continue;
}
printf("%2c", prnt);
}
nos = nos + 2;
printf("\n");
}
nos = 5;
for (i = 2; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
if (i == 5 && k == 5)
{ break;
}
printf("%2c", prnt);
}
nos = nos - 2;
printf("\n");
}
return 0;
}
(7)
#include <stdio.h>
int main()
{
char prnt = '*';
int i, j, k, s, nos = -1;
for (i = 5; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
if (i == 5 && k == 5)
{
continue;
}
printf("%2c", prnt);
}
nos = nos + 2;
printf("\n");
}
nos = 5;
for (i = 2; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
if (i == 5 && k == 5)
{
break;
}
printf("%2c", prnt);
}
nos = nos - 2;
printf("\n");
}
return 0;
}
(8)
#include <stdio.h>
int main()
{
char prnt = '*';
int i, j, k, s, sp, nos = 0, nosp = -1;
for (i = 9; i >= 3; (i = i - 2))
{
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
for (sp = nosp; sp >= 1; sp--)
{
printf(" ");
}
for (k = 1; k <= i; k++)
{
if (i == 9 && k == 1)
{
continue;
}
printf("%2c", prnt);
}
nos++;
nosp = nosp + 2;
printf("\n");
nos = 4;
for (i = 9; i >= 1; (i = i - 2))
{
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
printf("%2c", prnt);
}
nos++;
printf("\n");
}
return 0;
}
(9)
#include <stdio.h>
/* * nos = Num. of spaces required in the triangle. * i = Counter for the num. of
charcters to print in each row * skip= A flag for checking whether to * skip a
character in a row. * */
int triangle(int nos, int i, int skip)
{
char prnt = '*';
int s, j;
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
if (skip != 0)
{
if (i == 4 && j == 1)
{ continue;
}
}
printf("%2c", prnt);
}
return 0;
}
int main()
{
int i, nos = 4;
for (i = 1; i <= 7; (i = i + 2))
{
triangle(nos, i, 0);
nos--;
printf("\n");
}
nos = 5;
for (i = 1; i <= 4; i++)
{
triangle(1, i, 0); //one space needed in each case of the formation
triangle(nos, i, 1); //skip printing one star in the last row.
nos = nos - 2;
printf("\n");
}
nos = 1;
for (i = 3; i >= 1; i--)
{
triangle(1, i, 0);
triangle(nos, i, 0);
nos = nos + 2;
printf("\n");
}
nos = 1;
for (i = 7; i >= 1; (i = i - 2))
{
triangle(nos, i, 0);
nos++;
printf("\n");
}
return 0;
}
(10)
#include <stdio.h>
/* * nos = Num. of spaces required in the triangle. * i = Counter for the num. of
charcters to print in each row * skip= A flag for checking whether to * skip a
character in a row. * */
int triangle(int nos, int i, int skip)
{
char prnt = '*';
int s, j;
for (s = nos; s >= 1; s--)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
if (skip != 0)
{
if (i == 4 && j == 1)
{ continue;
}
}
printf("%2c", prnt);
}
return 0;
}
int main()
{
int i, nos = 4;
for (i = 1; i <= 7; (i = i + 2))
{
triangle(nos, i, 0);
nos--;
printf("\n");
}
nos = 5;
for (i = 1; i <= 4; i++)
{
triangle(1, i, 0); //one space needed in each case of the formation
triangle(nos, i, 1); //skip printing one star in the last row.
nos = nos - 2;
printf("\n");
}
nos = 1;
for (i = 3; i >= 1; i--)
{
triangle(1, i, 0);
triangle(nos, i, 0);
nos = nos + 2;
printf("\n");
}
nos = 1;
for (i = 7; i >= 1; (i = i - 2))
{
triangle(nos, i, 0);
nos++;
printf("\n");
}
return 0;
}
// This post is inspired by the great response to its first part.........................
// I hope the viewers will like these patterns again as they did for the previous post......
// Please let me know if any errors are encountered........