Initial commit
This commit is contained in:
27
c/Pattern_Programs/0 909 89098.c
Normal file
27
c/Pattern_Programs/0 909 89098.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
0
|
||||
909
|
||||
89098
|
||||
7890987
|
||||
678909876
|
||||
56789098765
|
||||
4567890987654
|
||||
345678909876543
|
||||
23456789098765432
|
||||
1234567890987654321
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
printf("0\n");
|
||||
for(i=9; i>=1; i--)
|
||||
{
|
||||
for(j=i; j<=9; j++)
|
||||
printf("%d",j);
|
||||
printf("0");
|
||||
for(j=9; j>=i; j--)
|
||||
printf("%d",j);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/1 12 123 1234.c
Normal file
13
c/Pattern_Programs/1 12 123 1234.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
31
c/Pattern_Programs/1 12 123....c
Normal file
31
c/Pattern_Programs/1 12 123....c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
1 1
|
||||
12 21
|
||||
123 321
|
||||
1234 4321
|
||||
1234554321
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j,k;
|
||||
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");
|
||||
}
|
||||
}
|
||||
28
c/Pattern_Programs/1 12 358 13 21 34 55.c
Normal file
28
c/Pattern_Programs/1 12 358 13 21 34 55.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
1
|
||||
1 2
|
||||
3 5 8
|
||||
13 21 34 55
|
||||
89 144 233 377 610
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int fib(int);
|
||||
void main()
|
||||
{
|
||||
int i,j,k=1;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d ",fib(k++));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int fib(int n)
|
||||
{
|
||||
if(n<=1)
|
||||
return n;
|
||||
return(fib(n-1)+fib(n-2));
|
||||
}
|
||||
38
c/Pattern_Programs/1 121 12321 1234321 1234321 12321 121 1.c
Normal file
38
c/Pattern_Programs/1 121 12321 1234321 1234321 12321 121 1.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
123454321
|
||||
1234321
|
||||
12321
|
||||
121
|
||||
1
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int num,r,c,sp;
|
||||
printf("Enter number of rows : ");
|
||||
scanf("%d",&num);
|
||||
for(r=1; r<=num; r++)
|
||||
{
|
||||
for(sp=num-r; sp>=1; sp--)
|
||||
printf(" ");
|
||||
for(c=1; c<=r; c++)
|
||||
printf("%d",c);
|
||||
for(c=r-1; c>=1; c--)
|
||||
printf("%d",c);
|
||||
printf("\n");
|
||||
}
|
||||
for(r=1; r<=num; r++)
|
||||
{
|
||||
for(sp=r; sp>=1; sp--)
|
||||
printf(" ");
|
||||
for(c=1; c<=(num-r); c++)
|
||||
printf("%d",c);
|
||||
for(c=num-r-1; c>=1; c--)
|
||||
printf("%d",c);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
19
c/Pattern_Programs/1 121 12321 1234321.c
Normal file
19
c/Pattern_Programs/1 121 12321 1234321.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
for(i=1; i<=4; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
printf("%d",j);
|
||||
for(j=i-1; j>=1; j--)
|
||||
printf("%d",j);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/1 21 321 4321 54321.c
Normal file
13
c/Pattern_Programs/1 21 321 4321 54321.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=i; j>=1; j--)
|
||||
{
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
37
c/Pattern_Programs/1 22 333 333 22 1.c
Normal file
37
c/Pattern_Programs/1 22 333 333 22 1.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
1
|
||||
2*2
|
||||
3*3*3
|
||||
4*4*4*4
|
||||
4*4*4*4
|
||||
3*3*3
|
||||
2*2
|
||||
1
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
for(i=1; i<=4; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
if(j<i)
|
||||
printf("%d*",i);
|
||||
else
|
||||
printf("%d",i);
|
||||
}
|
||||
printf(" \n");
|
||||
}
|
||||
for(i=4; i>=1; i--)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
if(j<i)
|
||||
printf("%d*",i);
|
||||
else
|
||||
printf("%d",i);
|
||||
}
|
||||
printf(" \n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/1 22 333 4444 55555.c
Normal file
13
c/Pattern_Programs/1 22 333 4444 55555.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d",i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
21
c/Pattern_Programs/1 24 135 2468 13579.c
Normal file
21
c/Pattern_Programs/1 24 135 2468 13579.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j,k;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
if(i%2==0)
|
||||
{
|
||||
k=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
k=1;
|
||||
}
|
||||
for(j=1; j<=i; j++,k+=2)
|
||||
{
|
||||
printf("%d ", k);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
25
c/Pattern_Programs/1 24 369 4 8 12 16.c
Normal file
25
c/Pattern_Programs/1 24 369 4 8 12 16.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
1
|
||||
2 4
|
||||
3 6 9
|
||||
4 8 12 16
|
||||
5 10 15 20 25
|
||||
6 12 18 24 30 36
|
||||
7 14 21 28 35 42 49
|
||||
8 16 24 32 40 48 56 64
|
||||
9 18 27 36 45 54 63 72 81
|
||||
10 20 30 40 50 60 70 80 90 100
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
for(i=1; i<=10; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d ",i*j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
17
c/Pattern_Programs/1 257 9 22 13 15 17 19.c
Normal file
17
c/Pattern_Programs/1 257 9 22 13 15 17 19.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
1
|
||||
3 5 7
|
||||
9 11 13 15 17 19
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int n=2,r,c,z=3;
|
||||
printf("1\n");
|
||||
for(r=1; r<=2; r++)
|
||||
{
|
||||
for(c=1; c<=r*3; c++,z=z+2)
|
||||
printf("%d ",z);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
37
c/Pattern_Programs/1..10 11...c
Normal file
37
c/Pattern_Programs/1..10 11...c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int a[10][10]= {0},i,j,low=0,top=9,n=1;
|
||||
for(i=0; i<5; i++,low++,top--)
|
||||
{
|
||||
for(j=low; j<=top; j++,n++)
|
||||
a[i][j]=n;
|
||||
for(j=low+1; j<=top; j++,n++)
|
||||
a[j][top]=n;
|
||||
for(j=top-1; j>=low; j--,n++)
|
||||
a[top][j]=n;
|
||||
for(j=top-1; j>low; j--,n++)
|
||||
a[j][low]=n;
|
||||
}
|
||||
printf("\t\t\tPerfect Square\n");
|
||||
for(i=0; i<10; i++)
|
||||
{
|
||||
printf("\n\n\t");
|
||||
for(j=0; j<10; j++)
|
||||
{
|
||||
printf("%6d",a[i][j]);
|
||||
delay(300);
|
||||
}
|
||||
}
|
||||
/*
|
||||
1 2 3 4 5 6 7 8 9 10
|
||||
36 37 38 39 40 41 42 43 44 11
|
||||
35 64 65 66 67 68 69 70 45 12
|
||||
34 63 84 85 86 87 88 71 46 13
|
||||
33 62 83 96 97 98 89 72 47 14
|
||||
32 61 82 95 100 99 90 73 48 15
|
||||
31 60 81 94 93 92 91 74 49 16
|
||||
30 59 80 79 78 77 76 75 50 17
|
||||
29 58 57 56 55 54 53 52 51 18
|
||||
28 27 26 25 24 23 22 21 20 19
|
||||
*/
|
||||
23
c/Pattern_Programs/1111 square.c
Normal file
23
c/Pattern_Programs/1111 square.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
11111
|
||||
1 1
|
||||
1 1
|
||||
1 1
|
||||
11111
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=1; j<=5; j++)
|
||||
{
|
||||
if(j==5 || j==1 || i==1 || i==5)
|
||||
printf("1");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
20
c/Pattern_Programs/11111 0000 111 00 1.c
Normal file
20
c/Pattern_Programs/11111 0000 111 00 1.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
11111
|
||||
0000
|
||||
111
|
||||
00
|
||||
1
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=5; i>=1; i--)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d",i%2);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/12345 1234 123 12 1.c
Normal file
13
c/Pattern_Programs/12345 1234 123 12 1.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=5; i>=1; i--)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/12345 2345 345 45 5.c
Normal file
13
c/Pattern_Programs/12345 2345 345 45 5.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=i; j<=5; j++)
|
||||
{
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
23
c/Pattern_Programs/5432 543 54.c
Normal file
23
c/Pattern_Programs/5432 543 54.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
5432*
|
||||
543*1
|
||||
54*21
|
||||
5*321
|
||||
*4321
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=5; j>=1; j--)
|
||||
{
|
||||
if(i==j)
|
||||
printf("*");
|
||||
else
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
13
c/Pattern_Programs/54321 4321 321 21 1.c
Normal file
13
c/Pattern_Programs/54321 4321 321 21 1.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=5; i>=1; i--)
|
||||
{
|
||||
for(j=i; j>=1; j--)
|
||||
{
|
||||
printf("%d",j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
14
c/Pattern_Programs/A AB ABCD ABCDE.c
Normal file
14
c/Pattern_Programs/A AB ABCD ABCDE.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
for(j=0; j<i; j++)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/A BA CBA DCBA.c
Normal file
14
c/Pattern_Programs/A BA CBA DCBA.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
for(j=i; j>=0; j--)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/A BB CCC DDDD EEEEE.c
Normal file
14
c/Pattern_Programs/A BB CCC DDDD EEEEE.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
for(j=0; j<=i; j++)
|
||||
{
|
||||
printf("%c",'A' + i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/AAAAA BBBB CCC DD E.c
Normal file
14
c/Pattern_Programs/AAAAA BBBB CCC DD E.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
{
|
||||
printf("%c",'A'+ i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/ABCDE ABCDE ABCDE.c
Normal file
14
c/Pattern_Programs/ABCDE ABCDE ABCDE.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=5; i>=1; i--)
|
||||
{
|
||||
for(j=0; j<5; j++)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/ABCDE BCDE CDE DE E.c
Normal file
14
c/Pattern_Programs/ABCDE BCDE CDE DE E.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
for(j=i; j<=4; j++)
|
||||
{
|
||||
printf("%c", 'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/E DD CCC BBBB AAAAA.c
Normal file
14
c/Pattern_Programs/E DD CCC BBBB AAAAA.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=4; i>=0; i--)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
{
|
||||
printf("%c",'A' + i);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/E DE CDE BCDE.c
Normal file
14
c/Pattern_Programs/E DE CDE BCDE.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=4; i>=0; i - -)
|
||||
{
|
||||
for(j=i; j<5; j++)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/E ED EDC EDCB.c
Normal file
14
c/Pattern_Programs/E ED EDC EDCB.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=4; i>=0; i--)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/EDCBA DCBA CBA BA A.c
Normal file
14
c/Pattern_Programs/EDCBA DCBA CBA BA A.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=4; i>=0; i--)
|
||||
{
|
||||
for(j=i; j>=0; j--)
|
||||
{
|
||||
printf("%c",'A'+ j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
14
c/Pattern_Programs/EDCBA EDCB EDC ED E.c
Normal file
14
c/Pattern_Programs/EDCBA EDCB EDC ED E.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i, j;
|
||||
for(i=0; i<=4; i++)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
{
|
||||
printf("%c",'A' + j);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
22
c/Pattern_Programs/Floyds triangle.c
Normal file
22
c/Pattern_Programs/Floyds triangle.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/*Floyd's triangle
|
||||
Floyd's triangle is a right angled-triangle using the natural numbers. Examples of Floyd’s triangle:
|
||||
Example
|
||||
1
|
||||
2 3
|
||||
4 5 6
|
||||
7 8 9 10
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j,r,k=1;
|
||||
printf("Enter the range: ");
|
||||
scanf("%d",&r);
|
||||
printf("FLOYD'S TRIANGLE\n\n");
|
||||
for(i=1; i<=r; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++,k++)
|
||||
printf(" %d",k);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
49
c/Pattern_Programs/P_111_333..c
Normal file
49
c/Pattern_Programs/P_111_333..c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Pattern Problem - Program to generate all combinations of 1 2 3 using for loop. (Eg Print 111(Row 1), (112)(Row 2), (113)(Row 3)...(333)(Last Row)) */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, k ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows:\n");
|
||||
for(i=1 ; i<=3 ; i++)
|
||||
for(j=1 ; j<=3 ; j++)
|
||||
for(k=1 ; k<=3 ; k++)
|
||||
printf("%d %d %d \n", i, j, k) ;
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1 1 1
|
||||
1 1 2
|
||||
1 1 3
|
||||
1 2 1
|
||||
1 2 2
|
||||
1 2 3
|
||||
1 3 1
|
||||
1 3 2
|
||||
1 3 3
|
||||
2 1 1
|
||||
2 1 2
|
||||
2 1 3
|
||||
2 2 1
|
||||
2 2 2
|
||||
2 2 3
|
||||
2 3 1
|
||||
2 3 2
|
||||
2 3 3
|
||||
3 1 1
|
||||
3 1 2
|
||||
3 1 3
|
||||
3 2 1
|
||||
3 2 2
|
||||
3 2 3
|
||||
3 3 1
|
||||
3 3 2
|
||||
3 3 3
|
||||
*/
|
||||
46
c/Pattern_Programs/P_123_12_1..c
Normal file
46
c/Pattern_Programs/P_123_12_1..c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Pattern problem
|
||||
...
|
||||
1 2 3 4
|
||||
1 2 3
|
||||
1 2
|
||||
1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=n ; i>=1 ; i--)
|
||||
{
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
/* If the pattern is fixed then variable 'n' should not be read
|
||||
|
||||
Space in printf should not be given if this is the pattern:
|
||||
1234
|
||||
123
|
||||
12
|
||||
1
|
||||
*/
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
1 2 3
|
||||
1 2
|
||||
1
|
||||
*/
|
||||
|
||||
|
||||
37
c/Pattern_Programs/P_123_23..c
Normal file
37
c/Pattern_Programs/P_123_23..c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Pattern problem
|
||||
...
|
||||
1 2 3 4
|
||||
2 3 4
|
||||
3 4
|
||||
4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=n ; i>=1 ; i--)
|
||||
{
|
||||
for(j=i ; j>=1 ; j--)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
3 2 1
|
||||
2 1
|
||||
1
|
||||
*/
|
||||
|
||||
51
c/Pattern_Programs/P_1_121..c
Normal file
51
c/Pattern_Programs/P_1_121..c
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=n ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=n-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d", j) ;
|
||||
/* Printing to the right of Centre */
|
||||
for(j=i-1 ; j>=1 ; j--)
|
||||
printf("%d", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Give one extra space in each printf() if the pattern is:
|
||||
1
|
||||
1 2 1
|
||||
1 2 3 2 1
|
||||
*/
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 4
|
||||
Required pattern is as follows:
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
*/
|
||||
59
c/Pattern_Programs/P_1_121_1..c
Normal file
59
c/Pattern_Programs/P_1_121_1..c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
12321
|
||||
121
|
||||
1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=4 ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=4-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d", j) ;
|
||||
/* Printing to the right of Centre */
|
||||
for(j=i-1 ; j>=1 ; j--)
|
||||
printf("%d", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
for(i=4-1 ; i>=1 ; i--)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=4-i ; j>=1 ; j--)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d", j) ;
|
||||
/* Printing to the right of Centre */
|
||||
for(j=i-1 ; j>=1 ; j--)
|
||||
printf("%d", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1
|
||||
121
|
||||
12321
|
||||
1234321
|
||||
12321
|
||||
121
|
||||
1
|
||||
*/
|
||||
42
c/Pattern_Programs/P_1_12A..c
Normal file
42
c/Pattern_Programs/P_1_12A..c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
1 2 A
|
||||
1 2 3 A B
|
||||
1 2 3 4 A B C
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr();
|
||||
printf("Required Pattern is as follows:\n");
|
||||
for(i=1 ; i<=4 ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=4-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Prinitng digits*/
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", j) ;
|
||||
/* Printing alphabets*/
|
||||
for(j=1 ; j<i ; j++)
|
||||
printf("%c ", j+64) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required Pattern is as follows:
|
||||
1
|
||||
1 2 A
|
||||
1 2 3 A B
|
||||
1 2 3 4 A B C
|
||||
*/
|
||||
|
||||
|
||||
44
c/Pattern_Programs/P_1_12_123..c
Normal file
44
c/Pattern_Programs/P_1_12_123..c
Normal file
@@ -0,0 +1,44 @@
|
||||
/* Pattern problem
|
||||
1
|
||||
1 2
|
||||
1 2 3
|
||||
1 2 3 4
|
||||
...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=n ; i++)
|
||||
{
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
/* If the pattern is fixed then variable 'n' should not be read
|
||||
|
||||
Space in printf should not be given if this is the pattern:
|
||||
1
|
||||
12
|
||||
123
|
||||
1234
|
||||
*/
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
1
|
||||
1 2
|
||||
1 2 3
|
||||
*/
|
||||
46
c/Pattern_Programs/P_1_21A..c
Normal file
46
c/Pattern_Programs/P_1_21A..c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
21A
|
||||
321AB
|
||||
4321ABC
|
||||
54321ABCD
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr();
|
||||
printf("Required Pattern is as follows:\n");
|
||||
for(i=1; i<=5; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=5-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Prinitng digits*/
|
||||
for(j=i ; j>=1 ; j--)
|
||||
printf("%d", j) ;
|
||||
/* Printing alphabets*/
|
||||
for(j=1 ; j<i ; j++)
|
||||
printf("%c", j+64) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required Pattern is as follows:
|
||||
1
|
||||
21A
|
||||
321AB
|
||||
4321ABC
|
||||
54321ABCD
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
39
c/Pattern_Programs/P_1_22..c
Normal file
39
c/Pattern_Programs/P_1_22..c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
2 2
|
||||
3 3 3
|
||||
4 4 4 4
|
||||
5 5 5 5 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=5 ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=5-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", i) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1
|
||||
2 2
|
||||
3 3 3
|
||||
4 4 4 4
|
||||
5 5 5 5 5
|
||||
*/
|
||||
37
c/Pattern_Programs/P_1_22_333 Normal..c
Normal file
37
c/Pattern_Programs/P_1_22_333 Normal..c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
2 2
|
||||
3 3 3
|
||||
4 4 4 4
|
||||
5 5 5 5 5
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=5 ; i++)
|
||||
{
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", i) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1
|
||||
2 2
|
||||
3 3 3
|
||||
4 4 4 4
|
||||
5 5 5 5 5
|
||||
|
||||
*/
|
||||
46
c/Pattern_Programs/P_1_232_34543..c
Normal file
46
c/Pattern_Programs/P_1_232_34543..c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Pattern Problem
|
||||
1
|
||||
2 3 2
|
||||
3 4 5 4 3
|
||||
4 5 6 7 6 5 4
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, k, n ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=4 ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=4-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(k=1, j=i ; k<=i ; k++, j++)
|
||||
printf("%d ", j) ;
|
||||
/* Printing to the right of Centre */
|
||||
for(k=1, j=j-2 ; k<=i-1 ; k++, j--)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1
|
||||
2 3 2
|
||||
3 4 5 4 3
|
||||
4 5 6 7 6 5 4
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
35
c/Pattern_Programs/P_1_23_456..c
Normal file
35
c/Pattern_Programs/P_1_23_456..c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Pattern problem
|
||||
1
|
||||
2 3
|
||||
4 5 6
|
||||
7 8 9 10
|
||||
...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, k ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
k=1 ;
|
||||
for(i=1 ; i<=4 ; i++)
|
||||
{
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%d ", k++) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
1
|
||||
2 3
|
||||
4 5 6
|
||||
7 8 9 10
|
||||
*/
|
||||
37
c/Pattern_Programs/P_321_21_1..c
Normal file
37
c/Pattern_Programs/P_321_21_1..c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Pattern problem
|
||||
...
|
||||
4 3 2 1
|
||||
3 2 1
|
||||
2 1
|
||||
1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=n ; i>=1 ; i--)
|
||||
{
|
||||
for(j=i ; j>=1 ; j--)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
3 2 1
|
||||
2 1
|
||||
1
|
||||
*/
|
||||
|
||||
46
c/Pattern_Programs/P_432_43_4..c
Normal file
46
c/Pattern_Programs/P_432_43_4..c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Pattern problem
|
||||
...
|
||||
4 3 2 1
|
||||
4 3 2
|
||||
4 3
|
||||
4
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=n ; i++)
|
||||
{
|
||||
for(j=n ; j>=i ; j--)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
/* If the pattern is fixed then variable 'n' should not be read
|
||||
|
||||
Space in printf should not be given if this is the pattern:
|
||||
4321
|
||||
432
|
||||
43
|
||||
4
|
||||
*/
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
3 2 1
|
||||
3 2
|
||||
3
|
||||
|
||||
*/
|
||||
|
||||
39
c/Pattern_Programs/P_4_43..c
Normal file
39
c/Pattern_Programs/P_4_43..c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* Pattern problem
|
||||
4
|
||||
4 3
|
||||
4 3 2
|
||||
4 3 2 1
|
||||
...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=n ; i>=1 ; i--)
|
||||
{
|
||||
for(j=n ; j>=i ; j--)
|
||||
printf("%d ", j) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 3
|
||||
Required pattern is as follows:
|
||||
3
|
||||
3 2
|
||||
3 2 1
|
||||
*/
|
||||
|
||||
|
||||
|
||||
37
c/Pattern_Programs/P_5_44_333..c
Normal file
37
c/Pattern_Programs/P_5_44_333..c
Normal file
@@ -0,0 +1,37 @@
|
||||
/* Pattern problem
|
||||
5
|
||||
4 4
|
||||
3 3 3
|
||||
2 2 2 2
|
||||
1 1 1 1 1
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=5 ; i>=1 ; i--)
|
||||
{
|
||||
for(j=5 ; j>=i ; j--)
|
||||
printf("%d ", i) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
5
|
||||
4 4
|
||||
3 3 3
|
||||
2 2 2 2
|
||||
1 1 1 1 1
|
||||
|
||||
|
||||
*/
|
||||
41
c/Pattern_Programs/P_ABC_AB_A..c
Normal file
41
c/Pattern_Programs/P_ABC_AB_A..c
Normal file
@@ -0,0 +1,41 @@
|
||||
/* Pattern Problem
|
||||
A B C D
|
||||
A B C
|
||||
A B
|
||||
A
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=4 ; i>=1 ; i--)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=4-i ; j>=1 ; j--)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%c ", j+64) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
A B C D
|
||||
A B C
|
||||
A B
|
||||
A
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
35
c/Pattern_Programs/P_A_AB_ABC..c
Normal file
35
c/Pattern_Programs/P_A_AB_ABC..c
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Pattern problem
|
||||
A
|
||||
A B
|
||||
A B C
|
||||
A B C D
|
||||
A B C D E
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=5 ; i++)
|
||||
{
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%c ", j+64) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
A
|
||||
A B
|
||||
A B C
|
||||
A B C D
|
||||
A B C D E
|
||||
*/
|
||||
46
c/Pattern_Programs/P_A_BB_CCC..c
Normal file
46
c/Pattern_Programs/P_A_BB_CCC..c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* Pattern Problem
|
||||
A
|
||||
B B
|
||||
C C C
|
||||
D D D D
|
||||
...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, n ;
|
||||
clrscr() ;
|
||||
printf("Enter the number of lines: ") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=n ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=n-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("%c ",i+64) ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter the number of lines: 4
|
||||
Required pattern is as follows:
|
||||
A
|
||||
B B
|
||||
C C C
|
||||
D D D D
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
52
c/Pattern_Programs/P_star..c
Normal file
52
c/Pattern_Programs/P_star..c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* Pattern Problem
|
||||
*
|
||||
* *
|
||||
* * *
|
||||
* *
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j ;
|
||||
clrscr() ;
|
||||
printf("Required pattern is as follows: \n") ;
|
||||
for(i=1 ; i<=3 ; i++)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=1 ; j<=3-i ; j++)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("* ") ;
|
||||
printf("\n") ;
|
||||
}
|
||||
for(i=3-1 ; i>=1 ; i--)
|
||||
{
|
||||
/* Managing spaces */
|
||||
for(j=3-i ; j>=1 ; j--)
|
||||
printf(" ") ;
|
||||
/* Printing from left to Centre */
|
||||
for(j=1 ; j<=i ; j++)
|
||||
printf("* ") ;
|
||||
printf("\n") ;
|
||||
}
|
||||
getch();
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Required pattern is as follows:
|
||||
*
|
||||
* *
|
||||
* * *
|
||||
* *
|
||||
*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
27
c/Pattern_Programs/P_x=1!..c
Normal file
27
c/Pattern_Programs/P_x=1!..c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* Pattern problem
|
||||
x=1!+3!+5!+7!+9!+...
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, n ;
|
||||
clrscr() ;
|
||||
printf("Enter n:") ;
|
||||
scanf("%d", &n) ;
|
||||
printf("Required Pattern is as shown:\n") ;
|
||||
printf("x=1!") ;
|
||||
for(i=3 ; i<=2*n-1 ; i=i+2)
|
||||
printf("+%d!", i) ;
|
||||
getch() ;
|
||||
}
|
||||
|
||||
/*
|
||||
Output:
|
||||
|
||||
Enter n:3
|
||||
Required Pattern is as shown:
|
||||
x=1!+3!+5!
|
||||
*/
|
||||
37
c/Pattern_Programs/Rhombus pattern with numbers.c
Normal file
37
c/Pattern_Programs/Rhombus pattern with numbers.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*design a number rhombus pattern
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
3 3
|
||||
2 2
|
||||
1 1
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int num,i,c,s,n;
|
||||
printf("Enter maximum number : ");
|
||||
scanf("%d", &num);
|
||||
for(i=1; i<=num; i++)
|
||||
{
|
||||
for(s=num-i; s>=1; s--)
|
||||
printf(" ");
|
||||
printf("%d", i);
|
||||
for(s=i*2; s>1; s--)
|
||||
printf(" ");
|
||||
printf("%d", i);
|
||||
printf("\n");
|
||||
}
|
||||
for(i=1,n=num-1; i<num; i++,n--)
|
||||
{
|
||||
for(s=i; s>=1; s--)
|
||||
printf(" ");
|
||||
printf("%d",n);
|
||||
for(s=n*2; s>1; s--)
|
||||
printf(" ");
|
||||
printf("%d", n);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
34
c/Pattern_Programs/Square with numbers.c
Normal file
34
c/Pattern_Programs/Square with numbers.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
4444444
|
||||
4333334
|
||||
4322234
|
||||
4321234
|
||||
4322234
|
||||
4333334
|
||||
4444444
|
||||
*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i,j,k;
|
||||
for(i=4; i>=1; i--)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
printf("%d",j);
|
||||
for(j=1; j<(i*2)-1; j++)
|
||||
printf("%d",i);
|
||||
for(j=i+1; j<=4; j++)
|
||||
printf("%d",j);
|
||||
printf("\n");
|
||||
}
|
||||
for(i=2; i<=4; i++)
|
||||
{
|
||||
for(j=4; j>=i; j--)
|
||||
printf("%d",j);
|
||||
for(j=1; j<(i*2)-1; j++)
|
||||
printf("%d",i);
|
||||
for(j=i+1; j<=4; j++)
|
||||
printf("%d",j);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
24
c/Pattern_Programs/Star 1.c
Normal file
24
c/Pattern_Programs/Star 1.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/*--
|
||||
|
||||
*
|
||||
**
|
||||
***
|
||||
****
|
||||
*****
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j, n;
|
||||
printf("Enter no. of rows: ");
|
||||
scanf("%d",&n);
|
||||
for(i=1; i<=n; i++)
|
||||
{
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
28
c/Pattern_Programs/Star 10.c
Normal file
28
c/Pattern_Programs/Star 10.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
|
||||
* * * *
|
||||
* * *
|
||||
* *
|
||||
*
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i,j,n;
|
||||
printf("Enter no. of row: ");
|
||||
scanf("%d",&n);
|
||||
for(i=1; i<=n; i++)
|
||||
{
|
||||
for(j=1; j<i; j++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for(j=i; j<=n; j++)
|
||||
{
|
||||
printf("* ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
28
c/Pattern_Programs/Star 2.c
Normal file
28
c/Pattern_Programs/Star 2.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*--
|
||||
|
||||
*
|
||||
**
|
||||
***
|
||||
****
|
||||
*****
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j, n;
|
||||
printf("Enter no. of rows: ");
|
||||
scanf("%d",&n);
|
||||
for(i=n; i>=1; i--)
|
||||
{
|
||||
for(j=1; j<i; j++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for(j=5; j>=i; j--)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
28
c/Pattern_Programs/Star 3.c
Normal file
28
c/Pattern_Programs/Star 3.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*--
|
||||
|
||||
*****
|
||||
****
|
||||
***
|
||||
**
|
||||
*
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j,n;
|
||||
printf("Enter no. of rows: ");
|
||||
scanf("%d",&n);
|
||||
for(i=n; i>=1; i--)
|
||||
{
|
||||
for(j=n; j>i; j--)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
28
c/Pattern_Programs/Star 4.c
Normal file
28
c/Pattern_Programs/Star 4.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*--
|
||||
|
||||
*
|
||||
***
|
||||
*****
|
||||
*******
|
||||
*********
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j, n;
|
||||
printf("Enter no. of rows: ");
|
||||
scanf("%d",&n);
|
||||
for(i=1; i<=n; i++)
|
||||
{
|
||||
for(j=i; j<n; j++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for(j=1; j<(i*2); j++)
|
||||
{
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
50
c/Pattern_Programs/Star 5.c
Normal file
50
c/Pattern_Programs/Star 5.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/*--
|
||||
|
||||
**********
|
||||
**** ****
|
||||
*** ***
|
||||
** **
|
||||
* *
|
||||
** **
|
||||
*** ***
|
||||
**** ****
|
||||
**********
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int i, j, k;
|
||||
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");
|
||||
}
|
||||
}
|
||||
33
c/Pattern_Programs/Star 6.c
Normal file
33
c/Pattern_Programs/Star 6.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
*
|
||||
**
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
************
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int num,r,j,s;
|
||||
printf("Enter no of rows: ");
|
||||
scanf("%d", &num);
|
||||
printf("\n*\n");
|
||||
for(r=1; r<=num; r++)
|
||||
{
|
||||
printf("*");
|
||||
for(s=1; s<r; s++)
|
||||
printf(" ");
|
||||
printf("*\n");
|
||||
}
|
||||
for(j=1; j<=num+2; j++)
|
||||
printf("*");
|
||||
}
|
||||
29
c/Pattern_Programs/Star 7.c
Normal file
29
c/Pattern_Programs/Star 7.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/*--
|
||||
|
||||
********
|
||||
* *
|
||||
* *
|
||||
********
|
||||
|
||||
--*/
|
||||
#include<stdio.h>
|
||||
void main()
|
||||
{
|
||||
int cols,rows,r,c,s;
|
||||
printf("Enter no. of columns: ");
|
||||
scanf("%d", &cols);
|
||||
printf("Enter no. of rows: ");
|
||||
scanf("%d", &rows);
|
||||
for(r=1; r<=cols; r++)
|
||||
printf("*");
|
||||
printf("\n");
|
||||
for(c=1; c<=rows-2; c++)
|
||||
{
|
||||
printf("*");
|
||||
for(s=1; s<=cols-2; s++)
|
||||
printf(" ");
|
||||
printf("*\n");
|
||||
}
|
||||
for(r=1; r<=cols; r++)
|
||||
printf("*");
|
||||
}
|
||||
33
c/Pattern_Programs/Star 8.c
Normal file
33
c/Pattern_Programs/Star 8.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
|
||||
* *
|
||||
** **
|
||||
* * *
|
||||
* *
|
||||
* *
|
||||
|
||||
|
||||
/* print m shape pyramid in c*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int num=5,j,i;
|
||||
for(i=1; i<=num; i++)
|
||||
{
|
||||
for(j=1; j<=num; j++)
|
||||
{
|
||||
if( (j==2 || j==3 || j==4) && (i==1) )
|
||||
printf(" ");
|
||||
else if( (j==3) && (i==2) )
|
||||
printf(" ");
|
||||
else if( (j==2 || j==4) && (i==3) )
|
||||
printf(" ");
|
||||
else if( (j==2 || j==3 || j==4 ) && (i==4 || i==5) )
|
||||
printf(" ");
|
||||
else
|
||||
printf("*");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
28
c/Pattern_Programs/Star 9.c
Normal file
28
c/Pattern_Programs/Star 9.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
|
||||
*
|
||||
* *
|
||||
* * *
|
||||
* * * *
|
||||
|
||||
*/
|
||||
#include<stdio.h>
|
||||
int main()
|
||||
{
|
||||
int i,j,n;
|
||||
printf("Enter value of n: ");
|
||||
scanf("%d",&n);
|
||||
for(i=1; i<=n; i++)
|
||||
{
|
||||
for(j=i; j<=n; j++)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
for(j=1; j<=i; j++)
|
||||
{
|
||||
printf("* ");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user