31. Pattern 11
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 5; j++)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
for (j = 5; j >= 1; j--)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
32. Floyd's triangle
1
2 3
4 5 6
7 8 9 10
11 12 13 14
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, c, a = 1;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (c = 1; c <= i; c++) {
printf("%d ", a);
a++;
}
printf("\n");
}
getch();
}
33. Pyramid
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int row, c, n, temp;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
temp = n;
for (row = 1; row <= n; row++)
{
for (c = 1; c < temp; c++)
printf(" ");
temp--;
for (c = 1; c <= 2 * row - 1; c++)
printf("*");
printf("\n");
}
getch();
}
34. Pyramid 2
*
A
A*A
A*A*A
A*A*A*A
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k, space, count = 1;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
space = n;
for (c = 1; c <= n; c++)
{
for (k = 1; k < space; k++)
printf(" ");
for (k = 1; k <= c; k++)
{
printf("*");
if (c > 1 && count < c)
{
printf("A");
count++;
}
}
printf("\n");
space--;
count = 1;
}
getch();
}
35. Number Pyramid
1
232
34543
4567654
567898765
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, d, num = 1, space;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
space = n - 1;
for (d = 1; d <= n; d++)
{
num = d;
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= d; c++)
{
printf("%d", num);
num++;
}
num--;
num--;
for (c = 1; c < d; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, k;
clrscr();
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= 5; j++)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
for (j = 5; j >= 1; j--)
{
if (j <= i)
{
printf("%d ", j);
}
else
{
printf(" ");
}
}
printf("\n");
}
getch();
}
32. Floyd's triangle
1
2 3
4 5 6
7 8 9 10
11 12 13 14
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, c, a = 1;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (c = 1; c <= i; c++) {
printf("%d ", a);
a++;
}
printf("\n");
}
getch();
}
33. Pyramid
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int row, c, n, temp;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
temp = n;
for (row = 1; row <= n; row++)
{
for (c = 1; c < temp; c++)
printf(" ");
temp--;
for (c = 1; c <= 2 * row - 1; c++)
printf("*");
printf("\n");
}
getch();
}
34. Pyramid 2
*
A
A*A
A*A*A
A*A*A*A
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, k, space, count = 1;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
space = n;
for (c = 1; c <= n; c++)
{
for (k = 1; k < space; k++)
printf(" ");
for (k = 1; k <= c; k++)
{
printf("*");
if (c > 1 && count < c)
{
printf("A");
count++;
}
}
printf("\n");
space--;
count = 1;
}
getch();
}
35. Number Pyramid
1
232
34543
4567654
567898765
#include<stdio.h>
#include<conio.h>
void main()
{
int n, c, d, num = 1, space;
clrscr();
printf("Enter the number of rows : ");
scanf("%d", &n);
space = n - 1;
for (d = 1; d <= n; d++)
{
num = d;
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= d; c++)
{
printf("%d", num);
num++;
}
num--;
num--;
for (c = 1; c < d; c++)
{
printf("%d", num);
num--;
}
printf("\n");
}
getch();
}
0 comments:
Post a Comment