41. Diamond of Numbers
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4
3 3 3 3 3
2 2 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = i; j < 5; j++)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("%d", i);
}
printf("\n");
}
for (i = 4; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("%d", i);
}
printf("\n");
}
getch();
}
42. Diamond Pattern
•
• • •
• • • • •
• • •
•
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k, space = 1;
clrscr();
printf("Enter number of rows : ");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2 * k - 1; c++)
printf("•");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1; c <= 2 * (n - k) - 1; c++)
printf("•");
printf("\n");
}
getch();
}
43. Diamond star outline
*
* *
* *
* *
* *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
printf("*");
for (j = 1; j < (i - 1) * 2; j++)
{
printf(" ");
}
if (i == 1)
{
printf("\n");
}
else
{ printf("*\n"); }
}
for (i = 4; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
printf("*");
for (j = 1; j < (i - 1) * 2; j++)
{
printf(" ");
}
if (i == 1)
{
printf("\n");
}
else
{ printf("*\n"); }
}
getch();
}
44. Hollow Diamond
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 6 - i; j++)
{
printf("*");
}
for (k = 1; k < i; k++)
{
printf(" ");
}
for (j = 1; j <= 6 - i; j++)
{
printf("*");
}
printf("\n");
}
for (i = 2; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("*");
}
for (k = 1; k <= 5 - i; k++)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}
getch();
}
45. Hollow Square
* * * * *
* *
* *
* *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, n;
clrscr();
printf("Enter value of n : ");
scanf("%d", &n);
printf("\n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (i != 1 && i != n && j != 1 && j != n)
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}
getch();
}
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
4 4 4 4 4 4 4
3 3 3 3 3
2 2 2
1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = i; j < 5; j++)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("%d", i);
}
printf("\n");
}
for (i = 4; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
for (k = 1; k < (i * 2); k++)
{
printf("%d", i);
}
printf("\n");
}
getch();
}
42. Diamond Pattern
•
• • •
• • • • •
• • •
•
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k, space = 1;
clrscr();
printf("Enter number of rows : ");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2 * k - 1; c++)
printf("•");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1; c <= 2 * (n - k) - 1; c++)
printf("•");
printf("\n");
}
getch();
}
43. Diamond star outline
*
* *
* *
* *
* *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
printf("*");
for (j = 1; j < (i - 1) * 2; j++)
{
printf(" ");
}
if (i == 1)
{
printf("\n");
}
else
{ printf("*\n"); }
}
for (i = 4; i >= 1; i--)
{
for (j = 5; j > i; j--)
{
printf(" ");
}
printf("*");
for (j = 1; j < (i - 1) * 2; j++)
{
printf(" ");
}
if (i == 1)
{
printf("\n");
}
else
{ printf("*\n"); }
}
getch();
}
44. Hollow Diamond
* * * * * * * *
* * * * * *
* * * *
* *
* * * *
* * * * * *
* * * * * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 6 - i; j++)
{
printf("*");
}
for (k = 1; k < i; k++)
{
printf(" ");
}
for (j = 1; j <= 6 - i; j++)
{
printf("*");
}
printf("\n");
}
for (i = 2; i <= 5; i++)
{
for (j = 1; j <= i; j++)
{
printf("*");
}
for (k = 1; k <= 5 - i; k++)
{
printf(" ");
}
for (j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}
getch();
}
45. Hollow Square
* * * * *
* *
* *
* *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, n;
clrscr();
printf("Enter value of n : ");
scanf("%d", &n);
printf("\n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (i != 1 && i != n && j != 1 && j != n)
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}
getch();
}
0 comments:
Post a Comment