46. Hourglass Pattern
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int num, n, r, c, sp;
clrscr();
printf("Enter number of rows: ");
scanf("%d", &num);
printf("\n");
n = num;
for (r = 1; r <= num; r++)
{
for (sp = 1; sp <= r; sp++)
printf(" ");
for (c = 1; c <= n; c++)
printf("*");
for (c = num - r; c >= 1; c--)
printf("*");
n--;
printf("\n");
}
for (r = 2; r <= num; r++)
{
for (sp = num - r + 1; sp >= 1; sp--)
printf(" ");
for (c = 1; c <= r; c++)
printf("*");
for (c = r - 1; c >= 1; c--)
printf("*");
printf("\n");
}
getch();
}
47. Nested Star-Hash Pyramid
#####*#####
#########
#########
#########
#########
#########
#include<stdio.h>
#include<conio.h>
void main()
{
int n = 5, r, c;
clrscr();
for (r = 1; r <= 6; r++, n--)
{
// first pyramid
for (c = 1; c <= n; c++)
{
printf(" #");
}
// second pyramid
for (c = 1; c <= r; c++)
{
if (c == 1)
{
printf(" *");
}
else
{
printf(" #");
}
}
// third pyramid
for (c = r; c > 1; c--)
{
if (c == 2)
{
printf(" *");
}
else
{
printf(" #");
}
}
// fourth pyramid
for (c = n; c >= 1; c--)
{
printf(" #");
}
printf("\n");
}
getch();
}
48. Reverse star pyramid
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 5; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("* ");
}
printf("\n");
}
getch();
}
49. Rhombus Pattern
1 1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1 1
#include<stdio.h>
#include<conio.h>
void main()
{
int num, r, c, sp, n;
clrscr();
printf("Enter the number : ");
scanf("%d", &num);
for (r = 1; r <= num; r++)
{
for (sp = num - r; sp >= 1; sp--)
printf(" ");
printf("%d", r);
for (sp = r * 2; sp > 1; sp--)
printf(" ");
printf("%d", r);
printf("\n");
}
for (r = 1, n = num - 1; r < num; r++, n--)
{
for (sp = r; sp >= 1; sp--)
printf(" ");
printf("%d", n);
for (sp = n * 2; sp > 1; sp--)
printf(" ");
printf("%d", n);
printf("\n");
}
getch();
}
50. Square kite pattern
1
2 2
3 3
4 4
3 3
2 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 4; i++)
{
for (j = 4; j >= (i - 1) * 2 - 1; j--)
printf(" ");
printf("%d", i);
for (j = 2; j <= (i - 1) * 4; j++)
printf(" ");
if (i > 1)
printf("%d", i);
printf("\n");
}
for (i = 3; i >= 1; i--)
{
for (j = 4; j >= (i - 1) * 2 - 1; j--)
printf(" ");
printf("%d", i);
for (j = 2; j <= (i - 1) * 4; j++)
printf(" ");
if (i > 1)
printf("%d", i);
printf("\n");
}
getch();
}
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int num, n, r, c, sp;
clrscr();
printf("Enter number of rows: ");
scanf("%d", &num);
printf("\n");
n = num;
for (r = 1; r <= num; r++)
{
for (sp = 1; sp <= r; sp++)
printf(" ");
for (c = 1; c <= n; c++)
printf("*");
for (c = num - r; c >= 1; c--)
printf("*");
n--;
printf("\n");
}
for (r = 2; r <= num; r++)
{
for (sp = num - r + 1; sp >= 1; sp--)
printf(" ");
for (c = 1; c <= r; c++)
printf("*");
for (c = r - 1; c >= 1; c--)
printf("*");
printf("\n");
}
getch();
}
47. Nested Star-Hash Pyramid
#####*#####
#########
#########
#########
#########
#########
#include<stdio.h>
#include<conio.h>
void main()
{
int n = 5, r, c;
clrscr();
for (r = 1; r <= 6; r++, n--)
{
// first pyramid
for (c = 1; c <= n; c++)
{
printf(" #");
}
// second pyramid
for (c = 1; c <= r; c++)
{
if (c == 1)
{
printf(" *");
}
else
{
printf(" #");
}
}
// third pyramid
for (c = r; c > 1; c--)
{
if (c == 2)
{
printf(" *");
}
else
{
printf(" #");
}
}
// fourth pyramid
for (c = n; c >= 1; c--)
{
printf(" #");
}
printf("\n");
}
getch();
}
48. Reverse star pyramid
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 5; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("* ");
}
printf("\n");
}
getch();
}
49. Rhombus Pattern
1 1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1 1
#include<stdio.h>
#include<conio.h>
void main()
{
int num, r, c, sp, n;
clrscr();
printf("Enter the number : ");
scanf("%d", &num);
for (r = 1; r <= num; r++)
{
for (sp = num - r; sp >= 1; sp--)
printf(" ");
printf("%d", r);
for (sp = r * 2; sp > 1; sp--)
printf(" ");
printf("%d", r);
printf("\n");
}
for (r = 1, n = num - 1; r < num; r++, n--)
{
for (sp = r; sp >= 1; sp--)
printf(" ");
printf("%d", n);
for (sp = n * 2; sp > 1; sp--)
printf(" ");
printf("%d", n);
printf("\n");
}
getch();
}
50. Square kite pattern
1
2 2
3 3
4 4
3 3
2 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 4; i++)
{
for (j = 4; j >= (i - 1) * 2 - 1; j--)
printf(" ");
printf("%d", i);
for (j = 2; j <= (i - 1) * 4; j++)
printf(" ");
if (i > 1)
printf("%d", i);
printf("\n");
}
for (i = 3; i >= 1; i--)
{
for (j = 4; j >= (i - 1) * 2 - 1; j--)
printf(" ");
printf("%d", i);
for (j = 2; j <= (i - 1) * 4; j++)
printf(" ");
if (i > 1)
printf("%d", i);
printf("\n");
}
getch();
}
0 comments:
Post a Comment