├── README.md ├── Q09.c ├── Q39.c ├── Q33.c ├── Q19.c ├── Q63.c ├── Q64.c ├── Q65.c ├── Q32.c ├── Q48.c ├── Q42.c ├── Q51.c ├── Q62.c ├── Q20.c ├── Q26.c ├── Q36.c ├── Q41.c ├── Q11.c ├── Q37.c ├── Q24.c ├── Q47.c ├── Q50.c ├── Q27.c ├── Q25.c ├── Q55.c ├── Q54.c ├── Q59.c ├── Q02.c ├── Q04.c ├── Q05.c ├── Q06.c ├── Q07.c ├── Q60.c ├── Q01.c ├── Q03.c ├── Q08.c ├── Q49.c ├── Q13.c ├── Q40.c ├── Q56.c ├── Q17.c ├── Q21.c ├── Q16.c ├── Q38.c ├── Q52.c ├── Q12.c ├── Q23.c ├── Q18.c ├── Q31.c ├── Q15.c ├── Q29.c ├── Q58.c ├── Q44.c ├── Q10.c ├── Q35.c ├── Q45.c ├── Q34.c ├── Q14.c ├── Q57.c ├── Q61.c ├── Q28.c ├── Q53.c ├── Q30.c ├── Q46.c ├── Q43.c ├── Q22.c └── 1_AllQuestionWithOutAnswerForPractice.txt /README.md: -------------------------------------------------------------------------------- 1 | # Number_Pattern_Question_Solving_Using_C 2 | In this repository, I will try to solve number pattern questions as much as I found. 3 | -------------------------------------------------------------------------------- /Q09.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 22 8 | 333 9 | 4444 10 | 55555 11 | */ 12 | for(int b = 1; b <= 5; b++ ){ 13 | for(int a = 1; a <= b; a++){ //another way --> for(int a = 0; a < b; a++) 14 | printf("%d",b); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q39.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 11111 7 | 0000 8 | 111 --explain--> use Q1 to understand 9 | 00 10 | 1 11 | */ 12 | 13 | for(int b = 5; b >= 1; b--){ 14 | for(int a = 1; a <= b; a++){ 15 | printf("%d", b%2); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q33.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 0 7 | 1 2 8 | 2 3 4 9 | 3 4 5 6 --explain--> do same things as Q32 10 | 4 5 6 7 8 11 | 5 6 7 8 9 10 12 | */ 13 | for(int b = 0; b <= 5; b++){ 14 | for(int a = 0; a <= b; a++){ 15 | printf("%d ", a+b); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q19.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 3 8 | 4 5 6 9 | 7 8 9 10 10 | */ 11 | int c=1; 12 | for(int b = 1; b<5; b++){ 13 | for(int a = 1; a <= b; a++){ 14 | printf("%d ",c++); // here we are addjng 1 with previous c for generate new numbers. 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q63.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 7 | 54 8 | 543 9 | 5432 10 | 54321 11 | */ 12 | 13 | for(int c = 5; c >= 1; c--){ 14 | for(int b = 1; b <= c - 1; b++){ 15 | printf(" "); 16 | } 17 | for(int a = 5; a >= c; a--){ 18 | printf("%d",a); 19 | } 20 | printf("\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Q64.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 21 8 | 321 9 | 4321 10 | 54321 11 | */ 12 | 13 | for(int c = 1; c <= 5; c++){ 14 | for(int b = 1; b <= 5 - c; b++){ 15 | printf(" "); 16 | } 17 | for(int a = c; a >= 1; a--){ 18 | printf("%d",a); 19 | } 20 | printf("\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Q65.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 7 | 45 8 | 345 9 | 2345 10 | 12345 11 | */ 12 | 13 | for(int c = 5; c >= 1; c--){ 14 | for(int b = 1; b <= c - 1; b++){ 15 | printf(" "); 16 | } 17 | for(int a = c; a <= 5; a++){ 18 | printf("%d",a); 19 | } 20 | printf("\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Q32.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 3 8 | 3 4 5 --explain--> same as Q31...... write here all equation as Q31(example - 1 = a + b) 9 | 4 5 6 7 10 | 5 6 7 8 9 11 | */ 12 | for( int b = 1; b <= 5; b++){ 13 | for(int a = 0; a < b; a++){ 14 | printf("%d ", a+b); //it is printing 1 to 9 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q48.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 11 8 | 121 9 | 1331 10 | 14641 11 | */ 12 | 13 | int multiplieBY11 = 1; 14 | for(int a = 1; a <= 5; a++){ 15 | if(a == 1){ 16 | printf("%d", multiplieBY11); 17 | } 18 | else{ 19 | printf("%d", multiplieBY11 *= 11); 20 | } 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Q42.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 1 2 8 | 1 2 3 9 | 1 2 3 4 10 | 1 2 3 4 5 11 | */ 12 | for(int c = 1; c <= 5; c++){ 13 | for(int a = 1; a <= 5-c; a++){ 14 | printf(" "); 15 | } 16 | for(int b = 1; b <= c; b++){ 17 | printf("%2d", b); 18 | } 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Q51.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 232 8 | 34543 9 | 4567654 10 | 567898765 11 | */ 12 | 13 | for(int c = 1; c <= 5; c++){ 14 | int d = c; 15 | for(int a = 1; a <= c; a++){ 16 | printf("%d", d++); 17 | } 18 | d-=2; 19 | for(int b = 1; b < c; b++){ 20 | printf("%d", d--); 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q62.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 12 8 | 123 9 | 1234 10 | 12345 11 | */ 12 | 13 | // int n = 1; 14 | for(int c = 1; c <= 5; c++){ 15 | for(int b = 1; b <= 5-c; b++){ 16 | printf(" "); 17 | } 18 | for(int a = 1; a <= c; a++){ 19 | printf("%d", a); 20 | } 21 | // n++; 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q20.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 6 8 | 3 7 10 9 | 4 8 11 13 10 | 5 9 12 14 15 11 | */ 12 | 13 | for(int a = 1; a <= 5; a++){ 14 | printf("%d ",a); 15 | int b = 4; 16 | int c = b + a; 17 | for(int j = 1; j < a; j++){ 18 | printf("%d ",c); 19 | b--; 20 | c += b; 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q26.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 121 8 | 12321 9 | 1234321 10 | 123454321 11 | */ 12 | for(int b = 1; b <= 9; b+=2){ 13 | for(int a = 1; a <= b; a++){ 14 | if( ((b+1)/2) >= a ){ 15 | printf("%d",a); 16 | } 17 | else{ 18 | printf("%d",b+1-a); 19 | } 20 | 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Q36.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 212 8 | 32123 9 | 4321234 10 | 543212345 11 | */ 12 | 13 | printf("%d\n",1); 14 | for( int c = 2; c <= 5; c++){ 15 | for(int a = c; a >= 2; a--){ 16 | printf("%d", a); 17 | } 18 | printf("%d",1); //print 1 in every line 19 | for(int b = 2; b <= c; b++){ 20 | printf("%d",b); 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q41.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 1 1 1 7 | 1 1 8 | 1 1 9 | 1 1 10 | 1 1 1 1 1 11 | */ 12 | for(int b = 1; b <= 5; b++){ 13 | for(int a = 1; a <= 5;a++){ 14 | if(b == 1 || b == 5 || a == 1 || a == 5){ 15 | printf("1 "); 16 | } 17 | else{ 18 | printf(" "); 19 | } 20 | } 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Q11.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 55555 5 -> b(start or initialise) 7 | 4444 4 -> b 8 | 333 explain --> for(int a = 1; a <= 3; a++) 9 | 22 2 -> b 10 | 1 1 -> b (end) 11 | **here we are printing b that way every line is same. 12 | */ 13 | for(int b = 5; b >= 1; b--){ 14 | for(int a = 1; a <= b; a++){ 15 | printf("%d",b); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q37.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 2 3 4 5 7 | 6 7 8 9 8 | 10 11 12 9 | 13 14 10 | 15 11 | */ 12 | 13 | int c = 1; 14 | for(int b = 5; b >= 1; b--){ 15 | for(int a = 1; a <= b; a++){ 16 | printf("%3d", c++); //%3d is used to occupied 3 place for 1 integer 17 | } 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // note -> here d++ means first do d = 1 then do d = d + 1 = 2; that's how 1 to 15 is printing 25 | -------------------------------------------------------------------------------- /Q24.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 11111 7 | 2222 8 | 333 9 | 22 10 | 1 11 | */ 12 | int c=1; 13 | for(int b = 5; b >= 1; b--){ 14 | for(int a = 1; a <= b; a++){ 15 | 16 | if(b >= 3){ 17 | printf("%d",c); 18 | } 19 | else{ 20 | int d = 6-c; 21 | printf("%d",d); 22 | } 23 | 24 | } 25 | c++; 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Q47.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 4 8 | 3 6 9 9 | 4 8 12 16 10 | 5 10 15 20 25 11 | 6 12 18 24 30 36 12 | 7 14 21 28 35 42 49 13 | 8 16 24 32 40 48 56 64 14 | 9 18 27 36 45 54 63 72 81 15 | 10 20 30 40 50 60 70 80 90 100 16 | */ 17 | 18 | for(int b = 1; b <= 10; b++){ 19 | for(int a = 1; a <= b; a++){ 20 | printf("%3d ",a*b); //%3d is used to occupied 3 place for 1 integer 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q50.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 3 2 8 | 4 5 6 9 | 10 9 8 7 10 | 11 12 13 14 15 11 | */ 12 | int c = 1, d = 1; 13 | for(int b = 1; b <= 5; b++){ 14 | d = c + b - 1; 15 | for(int a = 1; a <= b; a++){ 16 | if(b%2 == 1){ 17 | printf("%3d ", c); 18 | } 19 | else{ 20 | printf("%3d ", d--); 21 | } 22 | c++; 23 | } 24 | printf("\n"); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Q27.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 0 7 | 909 8 | 89098 9 | 7890987 10 | 678909876 11 | 56789098765 12 | 4567890987654 13 | 345678909876543 14 | 23456789098765432 15 | 1234567890987654321 16 | */ 17 | for(int c = 10; c >= 1; c--){ 18 | for(int a = c; a < 10; a++){ 19 | printf("%d ",a); 20 | } 21 | printf("O "); 22 | for(int b = 9; b >= c; b--){ 23 | printf("%d ", b); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Q25.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5432* 7 | 543*1 8 | 54*21 --explain--> it is a simple 5 x 5 pattern but when our b and a are equal(b == a) we have to print '*' 9 | 5*321 10 | *4321 11 | */ 12 | for(int b = 1; b <= 5; b++){ 13 | for(int a = 5; a >= 1; a--){ 14 | if(b == a){ 15 | printf("*"); 16 | } 17 | else{ 18 | printf("%d",a); 19 | } 20 | } 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Q55.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 1 2 1 8 | 1 2 3 2 1 9 | 1 2 3 4 3 2 1 10 | 1 2 3 4 5 4 3 2 1 11 | */ 12 | 13 | for(int d = 1; d <= 5; d++){ 14 | for(int a = 1; a <= 5-d; a++){ 15 | printf(" "); 16 | } 17 | for(int b = 1; b <= d; b++){ 18 | printf("%d ", b); 19 | } 20 | for(int c = d-1; c >= 1; c--){ 21 | printf("%d ",c); 22 | } 23 | printf("\n"); 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Q54.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 6 8 | 3 7 10 9 | 4 8 11 13 10 | 5 9 12 14 15 11 | */ 12 | 13 | 14 | for(int b = 1; b <= 5; b++){ 15 | int c = b, d = 4; 16 | for(int a = 1; a <= b; a++){ 17 | if(a == 1){ 18 | printf("%d ", c); 19 | } 20 | else{ 21 | c = c + d; 22 | printf("%d ", c); 23 | d--; 24 | } 25 | } 26 | c++; 27 | printf("\n"); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Q59.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | /* 5 | 86523 6 | 8652 7 | 865 8 | 86 9 | 8 10 | */ 11 | for(int b = 5; b >= 1; b--){ 12 | int c = 8, d = 2; 13 | for(int a = 1; a <= b; a++){ 14 | if(a == 1 || a == 2){ 15 | printf("%d",c); 16 | c-=2; 17 | } 18 | else if(a == 3){ 19 | printf("5"); 20 | } 21 | else{ 22 | printf("%d",d); 23 | d++; 24 | } 25 | } 26 | printf("\n"); 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Q02.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | 4 | /* 5 | 12345 1 -> b (start or initialise) 6 | 2345 2 -> b 7 | 345 ---> Explanation --> for(int a = 3; a <= 5; a++) 8 | 45 4 -> b 9 | 5 5 -> b (end) 10 | */ 11 | for(int b = 1; b<= 5; b++){ 12 | for(int a = b; a <= 5; a++){ 13 | printf("%d",a); 14 | } 15 | printf("\n"); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Q04.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 54321 1 -> b (start or initialise) 7 | 5432 2 -> b 8 | 543 ---> Explanation --> for(int a = 5; a >= 3; a--) 9 | 54 4 -> b 10 | 5 5 -> b (end) 11 | */ 12 | for(int b = 1; b <= 5; b++){ 13 | for(int a = 5; a >= b; a--){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q05.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 -> b (start or initialise) 7 | 12 2 -> b 8 | 123 ---> Explanation --> for(int a = 1; a <= 3; a++) 9 | 1234 4 -> b 10 | 12345 5 -> b (end) 11 | */ 12 | for(int b = 1;b <= 5; b++){ 13 | for(int a = 1; a <= b; a++){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q06.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 -> b (start or initialise) 7 | 45 4 -> b 8 | 345 ---> Explanation --> for(int a = 3; a <= 5; a++) 9 | 2345 2 -> b 10 | 12345 1 -> b (end) 11 | */ 12 | for(int b = 5; b >= 1; b--){ 13 | for(int a = b; a <= 5; a++){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q07.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 -> b (start or initialise) 7 | 21 2 -> b 8 | 321 ---> Explanation --> for(int a = 3; a >= 1; a--) 9 | 4321 4 -> b 10 | 54321 5 -> b (end) 11 | */ 12 | for(int b = 1; b <= 5; b++){ 13 | for(int a = b; a >= 1; a--){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q60.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 3 7 | 32 8 | 325 9 | 3256 10 | 32568 11 | */ 12 | 13 | for(int b = 1; b <= 5; b++){ 14 | int c = 3, d = 6; 15 | for(int a = 1; a <= b; a++){ 16 | if(a == 1 || a == 2){ 17 | printf("%d",c); 18 | c--; 19 | } 20 | else if(a == 3){ 21 | printf("5"); 22 | } 23 | else{ 24 | printf("%d",d); 25 | d+=2; 26 | } 27 | } 28 | printf("\n"); 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Q01.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | /* 5 | 12345 5 -> b (start or initialise) 6 | 1234 4 -> b 7 | 123 ---> Explanation --> for(int a = 1; a <= 3; a++) 8 | 12 2 -> b 9 | 1 1 -> b (end) 10 | */ 11 | 12 | for(int b = 5; b >= 1; b--){ 13 | for(int a = 1; a <= b; a++){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q03.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 54321 5 -> b (start or initialise) 7 | 4321 4 -> b 8 | 321 ---> Explanation --> for(int a = 3; a >= 1; a--) 9 | 21 2 -> b 10 | 1 1 -> b (end) 11 | */ 12 | for(int b = 5; b >= 1; b--){ 13 | for(int a = b; a >= 1; a--){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q08.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 -> b (start or initialise) 7 | 54 4 -> b 8 | 543 ---> Explanation --> for(int a = 5; a => 3; a--) 9 | 5432 2 -> b 10 | 54321 1 -> b (end) 11 | */ 12 | for(int b = 5; b >= 1; b--){ 13 | for(int a = 5; a >= b; a--){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q49.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 12345 1 + 2345 7 | 21234 21 + 234 8 | 32123 --devide into 2 pieces--> 321 + 23 9 | 43212 4321 + 2 10 | 54321 54321 11 | */ 12 | int c = 5; 13 | for(int b = 1; b <= 5; b++){ 14 | for(int a = b; a >= 1; a--){ 15 | printf("%d", a); 16 | } 17 | for(int a = 2; a <= c; a++){ 18 | printf("%d",a); 19 | } 20 | c--; 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Q13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1234567 7 -> b (start or initialise) 7 | 12345 explain --> for(int a = 1; a <= 5; a++) 8 | 123 3 -> b 9 | 1 1 -> b (end) 10 | ** after every line we do b = b - 2, for that we get 7, 5, 3, 1. 11 | */ 12 | for(int b = 7; b >= 1; b = b - 2){ 13 | for(int a = 1; a <= b; a++){ 14 | printf("%d",a); 15 | } 16 | printf("\n"); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Q40.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 4 9 16 8 | 25 36 49 64 81 9 | 100 121 144 169 196 225 256 10 | 289 324 361 400 441 484 529 576 625 11 | */ 12 | int d = 1, e = 0; 13 | for(int c = 1; c <= 5; c++){ 14 | for(int a = 1; a <= 5-c; a++){ 15 | printf(" "); 16 | } 17 | for(int b = 1; b <= c+e; b++){ 18 | printf("%3d ", d*d ); //%3d is used to occupie 3 place for 1 integer 19 | d++; 20 | } 21 | e++; 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Q56.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 2 8 | 3 3 9 | 4 4 10 | 5 5 11 | */ 12 | 13 | for(int c = 1; c <= 5; c++){ 14 | for(int a = 1; a <= 5-c; a++){ 15 | printf(" "); 16 | } 17 | for(int b = 1; b <= c; b++){ 18 | if(b == 1){ 19 | printf("%d ",c); 20 | } 21 | else if(b == c){ 22 | printf("%d ",c); 23 | } 24 | else{ 25 | printf(" "); 26 | } 27 | } 28 | printf("\n"); 29 | } 30 | 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Q17.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 4 8 | 1 3 5 9 | 2 4 6 8 10 | 1 3 5 7 9 11 | */ 12 | int c; 13 | for(int b = 1; b <= 5; b++){ //use this for 5 lines 14 | if(b%2 == 1){ 15 | c = 1; 16 | } 17 | else if(b%2 == 0){ 18 | c = 2; 19 | } 20 | for(int a = 1; a <= b; a++){ 21 | printf("%d ",c); 22 | c+=2; 23 | } 24 | printf("\n"); 25 | } 26 | 27 | return 0; 28 | } 29 | 30 | //Note --> for this question I have no excat explation how to do this, I think if u have basic knowladge of C u can do this. 31 | -------------------------------------------------------------------------------- /Q21.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 -> b (start or initialize) 7 | 123 3 8 | 12345 --explain--> for(int a = 1; a <= 5; a++) 9 | 1234567 7 10 | 123456789 9 -> b (end) 11 | here we are doing b = b + 2, for that reason we got 1, 3, 5, 7, 9. 12 | */ 13 | for(int b = 1; b <= 9; b += 2){ 14 | for(int a = 1; a <= b; a++){ 15 | printf("%d",a); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q16.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 13579 1 -> b (start or initialise) 7 | 3579 3 -> b 8 | 579 --explain--> for(int a = 5; a <= 9; a++) 9 | 79 7 -> b 10 | 9 9 -> b (end) 11 | after every line we are doing b = b + 2, for that we got 1, 3, 5, 7, 9 12 | */ 13 | for(int b = 1; b <= 9; b += 2){ 14 | for(int a = b; a <= 9 ; a += 2){ 15 | printf("%d",a); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q38.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | (use Q2) 7 | 12345 12345 + 8 | 23451 2345 + 1 9 | 34521 --devide it into 2 piece--> 345 + 21 10 | 45321 45 + 321 11 | 54321 5 + 4321 12 | */ 13 | 14 | for(int c = 1; c <= 5; c++){ 15 | for(int a = c; a <= 5; a++){ 16 | printf("%d",a); 17 | } 18 | for(int b = c-1; b >= 1; b--){ 19 | printf("%d", b); 20 | } 21 | printf("\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Q52.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 7 | 2 2 8 | 3 3 9 | 4 4 10 | 5 11 | */ 12 | int d = 5; 13 | for(int c = 1; c <= 5; c++){ 14 | 15 | for(int b = 1; b <= c-1; b++){ 16 | printf(" "); 17 | } 18 | for(int a = 5; a >= c; a--){ 19 | // printf("%d ",c); 20 | if(a == c){ 21 | printf("%d ",c); 22 | } 23 | else if(a == d){ 24 | printf("%d ",c); 25 | } 26 | else{ 27 | printf(" "); 28 | } 29 | } 30 | printf("\n"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Q12.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 11111 1 -> b (Start or initialise) 7 | 2222 2 -> b 8 | 333 explain --> for(int a = 1; a <= 6-3; a++) 9 | 44 4 -> b 10 | 5 5 -> b(end) 11 | here we are printing b, that's way every line have same number. 12 | */ 13 | for(int b = 1; b <= 5; b++){ 14 | for(int a = 1; a <= 6-b ; a++){ 15 | printf("%d",b); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | //another way --> 21 | for(int b = 1; b <= 5; b++){ 22 | for(int a = b; a <= 5 ; a++){ 23 | printf("%d",b); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Q23.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 --> b (start or initialize) <-- 1 7 | 2 3 4 --we need to make 2 loops--> (l1)for(int b = 1; b <= 3-2; b++) & (l2) for(int a = 1; a < 2 * 2; a++) 8 | 5 6 7 8 9 3 --> b (end) <-- 3 9 | 10 | */ 11 | int e = 1; 12 | for(int c=1; c <= 3;c++){ 13 | for(int b = 1; b<= 3-c; b++){ 14 | printf(" "); 15 | } 16 | for(int a = 1; a 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 5 5 5 5 * * * * 7 | 4 5 5 5 5 4 5 * * * 8 | 3 4 5 5 5 -- we can write this way--> 3 4 5 * * --> now we can use explation of Q06 for the number part and for '*' part we need to use another loop 9 | 2 3 4 5 5 2 3 4 5 * 10 | 1 2 3 4 5 1 2 3 4 5 11 | */ 12 | for(int b = 5; b >= 1; b--){ 13 | for(int a = b; a <= 5; a++){ 14 | printf("%d ",a); 15 | } 16 | for(int c = 1; c <= b - 1; c++){ 17 | printf("%d ",5); 18 | } 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Q31.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 11 11 = 9 + 1(a) + 1(b) 7 | 12 13 12 = 9 + 1(a) + 2(b); 13 = 9 + 2(a) + 2(b) 8 | 13 14 15 --explain--> 13 = 9 + 1(a) + 3(b); 14 = 9 + 2(a) + 3(b); 15 = 9 + 3(a) + 3(b) 9 | 14 15 16 17 13 = 9 + 1(a) + 4(b);.......Fill this by yourself......;17 = 9 + 4(a) + 4(b) 10 | 15 16 17 18 19 15 = 9 + 1(a) + 5(b);...........Fill this by yourself...........;19 = 9 + 5(a) + 5(b) 11 | */ 12 | 13 | for(int b = 1; b <= 5; b++){ 14 | for(int a = 1; a <= b; a++){ 15 | printf("%d ", 9+a+b); // 9+a+b is printing 11 to 19 16 | } 17 | printf("\n"); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Q15.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 7 | 10 12 8 | 101 --we can write this way--> 123 --we are using explanation of Q05. 9 | 1010 1234 10 | 10101 12345 11 | --Explain--> now here we use % to identify odd and even number, if number is even a%2 print 0(that means false) and if number is odd a%2 print 1(that means true). 12 | 13 | */ 14 | for(int b = 1; b <= 5; b++){ 15 | for(int a = 1; a <= b; a++){ 16 | printf("%d",a%2); 17 | } 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | //**Note --> there are another way to do this, find that by yourself. If u able to do that please massage me on linkedin or insta. 25 | -------------------------------------------------------------------------------- /Q29.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 -> c (start or initialize)<- 1 7 | 21 2 -> c <- 2 8 | 321 --2 different loops--> (l1) for(int a = 1; a <= 5-3; a++) & (l2) for(int b = 3; b >= 1; b--) 9 | 4321 4 -> c <- 4 10 | 54321 5 -> c (End) <- 5 11 | */ 12 | for(int c = 1; c <= 5; c++){ 13 | for(int a = 1; a <= 5-c; a++){ 14 | printf(" "); 15 | } 16 | for(int b = c; b >= 1; b--){ 17 | printf("%d",b); 18 | } 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Q58.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 2 3 4 5 7 | 16 6 8 | 15 7 9 | 14 8 10 | 13 12 11 10 9 11 | */ 12 | int c = 16, d = 6; 13 | for(int a = 1; a <= 5; a++){ 14 | printf("%2d ", a); 15 | } 16 | printf("\n"); 17 | for(int b = 1; b <= 3; b++){ 18 | for(int a = 1; a <= 5; a++){ 19 | if(a == 1){ 20 | printf("%2d ",c); 21 | } 22 | else if(a == 5){ 23 | printf("%2d ",d); 24 | } 25 | else{ 26 | printf(" "); 27 | } 28 | } 29 | c--; 30 | d++; 31 | printf("\n"); 32 | } 33 | for(int a = 13; a >= 9; a--){ 34 | printf("%2d ",a); 35 | } 36 | printf("\n"); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Q44.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | *OOO*OOO* *OOO + * + OOO* 7 | O*OO*OO*O --devide into 3 piece--> O*OO + * + OO*O 8 | OO*O*O*OO OO*O + * + O*OO 9 | OOO***OOO OOO* + * + *OOO 10 | */ 11 | 12 | for(int b = 1; b <= 4; b++){ 13 | for(int a = 1; a <= 4; a++){ 14 | if (b == a){ 15 | printf("*"); 16 | } 17 | else{ 18 | printf("O"); 19 | } 20 | } 21 | printf("*"); 22 | for(int a = 4; a >= 1; a--){ 23 | if(b == a){ 24 | printf("*"); 25 | } 26 | else{ 27 | printf("O"); 28 | } 29 | } 30 | printf("\n"); 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Q10.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 -> b 7 | 44 4 -> b 8 | 333 explain --> for(int a = 1; a <= 6-3; a++) 9 | 2222 2 -> b 10 | 11111 1 -> b 11 | here we are printing b, that's why every line have same number. 12 | */ 13 | for(int b = 5; b >= 1; b--){ 14 | for(int a = 1; a <= 6-b; a++){ 15 | printf("%d",b); 16 | } 17 | printf("\n"); 18 | } 19 | 20 | //another way --> 21 | for(int b = 5; b >= 1; b--){ 22 | for(int a = b; a <= 5; a++){ 23 | printf("%d",b); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Q35.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 --> c (start or initialise) <-- 5 7 | 5 4 4 --> c <-- 4 8 | 5 4 3 --explain--> (print space)-> for(int a = 3-1; a >= 1; a--) + (print number)-> for(int b = 5; b >= 3; b--) 9 | 5 4 3 2 2 --> c <-- 2 10 | 5 4 3 2 1 1 --> c (end) <-- 1 11 | */ 12 | for(int c = 5; c >= 1; c--){ 13 | for(int a = c-1; a >= 1; a--){ 14 | printf(" "); 15 | } 16 | for(int b = 5; b >= c; b--){ 17 | printf("%d ",b); 18 | } 19 | printf("\n"); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Q45.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 5 5 5 5 5 5 5 5 5 5 5 5 + 5 5 5 5 7 | 5 4 4 4 4 4 4 4 5 5 4 4 4 4 + 4 4 4 5 8 | 5 4 3 3 3 3 3 4 5 --break it into 2 pieces--> 5 4 3 3 3 + 3 3 4 5 9 | 5 4 3 2 2 2 3 4 5 5 4 3 2 2 + 2 3 4 5 10 | 5 4 3 2 1 2 3 4 5 5 4 3 2 1 + 2 3 4 5 11 | */ 12 | 13 | int c = 5; 14 | for(int b = c; b >= 1; b--){ 15 | //first piece 16 | for(int a = c; a >= 1; a--){ 17 | if (a>b){ 18 | printf("%d",a); 19 | } 20 | else{ 21 | printf("%d",b); 22 | } 23 | } 24 | //second piece 25 | for(int a = 2; a <= c; a++){ 26 | if(a>b){ 27 | printf("%d",a); 28 | } 29 | else{ 30 | printf("%d",b); 31 | } 32 | } 33 | printf("\n"); 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Q34.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 --> c (start or initialise) <-- 1 7 | 2 3 2 --> c <-- 2 8 | 4 5 6 --explain--> (printing space)-> for(int a = 1; a <= 5 - 3; a++) + (printing number)-> for(int b = 3; b >= 1; b--) 'Note-> a & b are using as position' 9 | 7 8 9 10 4 --> c <-- 4 10 | 11 12 13 14 15 5 --> c(end) <-- 5 11 | */ 12 | int d = 1; 13 | for(int c = 1; c <= 5; c++){ 14 | for(int a = 1; a <= 5-c; a++){ 15 | printf(" "); 16 | } 17 | for(int b = c; b >= 1; b--){ 18 | printf("%3d",d++); //d is used to print a increasing values 19 | } 20 | printf("\n"); 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | // note -> here d++ means first do d = 1 then do d = d + 1 = 2; that's how 1 to 15 is printing 27 | -------------------------------------------------------------------------------- /Q14.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | (I) (II) 7 | 1 1 5 8 | 01 21 45 9 | 101 --we can write this way--> 321 --Or--> 345 --> we use explanation of Q07 & Q08. 10 | 0101 4321 2345 11 | 10101 54321 12345 12 | 13 | (I) --Explain--> now here we use % to identify odd and even number, if number is even a%2 print 0(that means false) and if number is odd a%2 print 1(that means true). 14 | (II) --Explain--> now here we use % to identify odd and even number, if number is even a%2 print 0(that means false) and if number is odd a%2 print 1(that means true). 15 | */ 16 | 17 | //using (I) method -> 18 | for(int b = 1; b <= 5; b++){ 19 | for(int a = b; a >= 1; a-- ){ 20 | printf("%d",a%2); 21 | } 22 | printf("\n"); 23 | } 24 | 25 | // using (II) method -> 26 | for(int b = 5; b >= 1; b--){ 27 | for(int a = b; a <= 5; a++ ){ 28 | printf("%d",a%2); 29 | } 30 | printf("\n"); 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Q57.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 7 | 2 2 8 | 3 3 9 | 4 4 10 | 5 5 11 | 4 4 12 | 3 3 13 | 2 2 14 | 1 15 | */ 16 | 17 | for(int c = 1; c <= 5; c++){ 18 | for(int a = 1; a <= 5-c; a++){ 19 | printf(" "); 20 | } 21 | for(int b = 1; b <= c; b++){ 22 | if(b == 1){ 23 | printf("%d ",c); 24 | } 25 | else if(b == c){ 26 | printf("%d ",c); 27 | } 28 | else{ 29 | printf(" "); 30 | } 31 | } 32 | printf("\n"); 33 | } 34 | 35 | //2nd part 36 | for(int c = 4; c >= 1; c--){ 37 | for(int a = 1; a <= 5-c; a++){ 38 | printf(" "); 39 | } 40 | for(int b = 1; b <= c; b++){ 41 | if(b == 1){ 42 | printf("%d ",c); 43 | } 44 | else if(b == c){ 45 | printf("%d ",c); 46 | } 47 | else{ 48 | printf(" "); 49 | } 50 | } 51 | printf("\n"); 52 | } 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /Q61.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 2 3 4 5 6 7 8 9 10 7 | 36 37 38 39 40 41 42 43 44 11 8 | 35 64 65 66 67 68 69 70 45 12 9 | 34 63 84 85 86 87 88 71 46 13 10 | 33 62 83 96 97 98 89 72 47 14 11 | 32 61 82 95 100 99 90 73 48 15 12 | 31 60 81 94 93 92 91 74 49 16 13 | 30 59 80 79 78 77 76 75 50 17 14 | 29 58 57 56 55 54 53 52 51 18 15 | 28 27 26 25 24 23 22 21 20 19 16 | */ 17 | 18 | 19 | int a[10][10], i, j; 20 | int low = 0, high = 9, n = 1; 21 | for(i=0; i<5; i++, low++, high--){ 22 | for(j=low; j<=high; j++, n++) 23 | a[i][j] = n; 24 | for(j=low+1; j<=high; j++, n++) 25 | a[j][high] = n; 26 | for(j=high-1; j>=low; j--, n++) 27 | a[high][j] = n; 28 | for(j=high-1; j>low; j--, n++) 29 | a[j][low] = n; 30 | } 31 | printf("\t\tPerfect Square Spiral\n"); 32 | for(i=0; i<10; i++){ 33 | printf("\n"); 34 | for(j=0; j<10; j++) 35 | printf("%4d", a[i][j]); 36 | } 37 | printf("\n"); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Q28.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 1 (start or initialize) b <- 1 + ******** + 1 1 -> b (start or initialize) 7 | 12 21 12 b <- 2 + ****** + 21 2 -> b 8 | 123 321 --devided into 3 pieces --> 123 --> for(int a = 1; a <= 3; a++) + **** + 321 --> for(int c = 3; c >= 1; c++) 9 | 1234 4321 1234 b <- 4 + ** + 4321 4 -> b 10 | 1234554321 12345 (End) b <- 5 + + 54321 5 -> b (End) 11 | */ 12 | for(int d = 1; d <= 5; d++){ 13 | for(int a = 1; a <= d; a++){ 14 | printf("%d",a); 15 | } 16 | for(int b = (5-d) * 2; b >= 1; b--){ //loop for '*' 17 | printf(" "); 18 | } 19 | for(int c = d; c >= 1; c--){ 20 | printf("%d",c); 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | 28 | //Note --> we can also devided it into 4 pieces......try it by yourself and massage me on linkdin or insta 29 | -------------------------------------------------------------------------------- /Q53.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 1 7 | 2 2 8 | 3 3 9 | 4 4 10 | 5 11 | 4 4 12 | 3 3 13 | 2 2 14 | 1 1 15 | */ 16 | 17 | // part 1 18 | int d = 5; 19 | for(int c = 1; c <= 5; c++){ 20 | 21 | for(int b = 1; b <= c-1; b++){ 22 | printf(" "); 23 | } 24 | for(int a = 5; a >= c; a--){ 25 | if(a == c){ 26 | printf("%d ",c); 27 | } 28 | else if(a == d){ 29 | printf("%d ",c); 30 | } 31 | else{ 32 | printf(" "); 33 | } 34 | } 35 | printf("\n"); 36 | } 37 | 38 | //part 2 39 | int e = 1; 40 | for(int c = 2; c <= 5; c++){ 41 | d--; 42 | for(int b = 5-c; b >= 1; b--){ 43 | printf(" "); 44 | } 45 | for(int a = 1; a <= c; a++){ 46 | if(a == e){ 47 | printf("%d ", d); 48 | } 49 | else if(a == c){ 50 | printf("%d ", d); 51 | } 52 | else{ 53 | printf(" "); 54 | } 55 | } 56 | printf("\n"); 57 | } 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /Q30.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 --> start of first half 7 | 2*2 8 | 3*3*3 9 | 4*4*4*4 10 | 5*5*5*5*5 11 | 4*4*4*4 --> start of second half 12 | 3*3*3 13 | 2*2 14 | 1 15 | */ 16 | int i=1, j=4; 17 | //first half 18 | for(int b = 1; b <= 10; b+=2){ 19 | for(int a = b; a >= 1; a--){ 20 | if(a%2 == 1){ // it means --> if the position(a) is odd print the value of i 21 | printf("%d",i); 22 | } 23 | else if(a%2 == 0){ // it means --> if the position(a) is even print '*' 24 | printf("*"); 25 | } 26 | } 27 | i++; //every time we need to increase the value upto 5 28 | printf("\n"); 29 | } 30 | //second half 31 | for(int c = 7; c >= 1; c-=2){ 32 | for(int a = 1; a <= c; a++){ 33 | if(a%2 == 1){ // it means --> if the position(a) is odd print the value of j 34 | printf("%d",j); 35 | } 36 | else if(a%2 == 0){ // it means --> if the position(a) is even print '*' 37 | printf("*"); 38 | } 39 | } 40 | j--; //every time we need to decrease the value upto 1 41 | printf("\n"); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /Q46.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 5 5 5 5 5 5 5 5 5 7 | 5 4 4 4 4 4 4 4 5 8 | 5 4 3 3 3 3 3 4 5 9 | 5 4 3 2 2 2 3 4 5 10 | 5 4 3 2 1 2 3 4 5 11 | 5 4 3 2 2 2 3 4 5 12 | 5 4 3 3 3 3 3 4 5 13 | 5 4 4 4 4 4 4 4 5 14 | 5 5 5 5 5 5 5 5 5 15 | */ 16 | 17 | int c = 5; 18 | for(int b = c; b >= 1; b--){ 19 | for(int a = c; a >= 1; a--){ 20 | if (a>b){ 21 | printf("%d",a); 22 | } 23 | else{ 24 | printf("%d",b); 25 | } 26 | } 27 | for(int a = 2; a <= c; a++){ 28 | if(a>b){ 29 | printf("%d",a); 30 | } 31 | else{ 32 | printf("%d",b); 33 | } 34 | } 35 | printf("\n"); 36 | } 37 | 38 | for(int b = 2; b <= c; b++){ 39 | for(int a = c; a >= 1; a--){ 40 | if (a>b){ 41 | printf("%d",a); 42 | } 43 | else{ 44 | printf("%d",b); 45 | } 46 | } 47 | for(int a = 2; a <= c; a++){ 48 | if(a>b){ 49 | printf("%d",a); 50 | } 51 | else{ 52 | printf("%d",b); 53 | } 54 | } 55 | printf("\n"); 56 | } 57 | 58 | 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /Q43.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | 1 //start of 1st half 7 | 123 8 | 12345 9 | 1234567 10 | 123456789 //end of 1st half 11 | 1234567 //start of 2nd half 12 | 12345 13 | 123 14 | 1 //end of 2nd half 15 | */ 16 | int d = 0; 17 | //first half 18 | for(int c = 1; c <= 5; c++){ 19 | for(int a = 1; a <= 5-c; a++){ 20 | printf(" "); 21 | } 22 | for(int b = 1; b <= c+d; b++){ 23 | printf("%d",b); 24 | } 25 | d++; 26 | printf("\n"); 27 | } 28 | 29 | //second half 30 | int e = 3; 31 | for(int c = 4; c >= 1; c--){ 32 | for(int a = 5-c; a >= 1; a--){ 33 | printf(" "); 34 | } 35 | for(int b = 1; b <= c+e; b++){ 36 | printf("%d",b); 37 | } 38 | e--; 39 | printf("\n"); 40 | } 41 | 42 | 43 | 44 | // ANOTHER WAY--> 45 | //first half 46 | for(int c = 1; c <= 5; c++){ 47 | for(int a = 1; a <= 5-c; a++){ 48 | printf(" "); 49 | } 50 | for(int b = 1; b < c*2; b++){ 51 | printf("%d",b); 52 | } 53 | printf("\n"); 54 | } 55 | 56 | //second half 57 | for(int c = 4; c >= 1; c--){ 58 | for(int a = 5-c; a >= 1; a--){ 59 | printf(" "); 60 | } 61 | for(int b = 1; b < c*2; b++){ 62 | printf("%d",b); 63 | } 64 | printf("\n"); 65 | } 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /Q22.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | 5 | /* 6 | (I) (II) (III) 7 | 1234554321 12345 (start or initialize) d <- 5 54321 5 -> d (start or initialize) 8 | 1234**4321 1234 d <- 4 ** 4321 4 -> d 9 | 123****321 --devided it into 3 pieces--> 123 --Explain--> for(int a = 1; a <= 3; a++) + **** + 321 --explain III--> for(int c = 3; c >= 1; c--) 10 | 12******21 12 d <- 2 + ****** + 21 2 -> d 11 | 1********1 1 (End) d <- 1 + ******** + 1 1 -> d (End) 12 | 13 | (I) --> follow Q01 14 | */ 15 | for(int d = 5; d >= 1; d--){ 16 | for(int a = 1; a <= d; a++){ 17 | printf("%d",a); 18 | } 19 | for(int b = 1; b <= (5 - d) * 2; b++){ 20 | printf("*"); 21 | } 22 | for(int c = d; c >= 1; c--){ 23 | printf("%d",c); 24 | } 25 | printf("\n"); 26 | } 27 | 28 | // another way --> **devided the pattern into 4 pieces(make the pattern and massage me) 29 | for(int e = 5; e >= 1; e--){ 30 | for(int a = 1; a <= e; a++){ 31 | printf("%d",a); 32 | } 33 | for(int b = 1; b <= 5 - e; b++){ 34 | printf("*"); 35 | } 36 | for(int c = 1; c <= 5 - e; c++){ 37 | printf("*"); 38 | } 39 | for(int d = e; d >= 1; d--){ 40 | printf("%d",d); 41 | } 42 | printf("\n"); 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /1_AllQuestionWithOutAnswerForPractice.txt: -------------------------------------------------------------------------------- 1 | If any one want to solve questions before seeing the answer of it......so here it is All question together for u. 2 | 3 | Q. Print every question on screen using C language. 4 | 5 | Q01. 6 | 7 | 12345 8 | 1234 9 | 123 10 | 12 11 | 1 12 | 13 | Q02. 14 | 15 | 12345 16 | 2345 17 | 345 18 | 45 19 | 5 20 | 21 | Q03. 22 | 23 | 54321 24 | 4321 25 | 321 26 | 21 27 | 1 28 | 29 | Q04. 30 | 31 | 54321 32 | 5432 33 | 543 34 | 54 35 | 5 36 | 37 | Q05. 38 | 39 | 1 40 | 12 41 | 123 42 | 1234 43 | 12345 44 | 45 | Q06. 46 | 47 | 5 48 | 45 49 | 345 50 | 2345 51 | 12345 52 | 53 | Q07. 54 | 55 | 1 56 | 21 57 | 321 58 | 4321 59 | 54321 60 | 61 | Q08. 62 | 63 | 5 64 | 54 65 | 543 66 | 5432 67 | 54321 68 | 69 | Q09. 70 | 71 | 1 72 | 22 73 | 333 74 | 4444 75 | 55555 76 | 77 | Q10. 78 | 79 | 5 80 | 44 81 | 333 82 | 2222 83 | 11111 84 | 85 | Q11. 86 | 87 | 55555 88 | 4444 89 | 333 90 | 22 91 | 1 92 | 93 | Q12. 94 | 95 | 11111 96 | 2222 97 | 333 98 | 44 99 | 5 100 | 101 | Q13. 102 | 103 | 1234567 104 | 12345 105 | 123 106 | 1 107 | 108 | Q14. 109 | 110 | 1 111 | 01 112 | 101 113 | 0101 114 | 10101 115 | 116 | Q15. 117 | 118 | 1 119 | 10 120 | 101 121 | 1010 122 | 10101 123 | 124 | Q16. 125 | 126 | 13579 127 | 3579 128 | 579 129 | 79 130 | 9 131 | 132 | Q17. 133 | 134 | 1 135 | 2 4 136 | 1 3 5 137 | 2 4 6 8 138 | 1 3 5 7 9 139 | 140 | Q18. 141 | 142 | 5 5 5 5 5 143 | 4 5 5 5 5 144 | 3 4 5 5 5 145 | 2 3 4 5 5 146 | 1 2 3 4 5 147 | 148 | Q19. 149 | 150 | 1 151 | 2 3 152 | 4 5 6 153 | 7 8 9 10 154 | 155 | Q20. 156 | 157 | 1 158 | 2 3 159 | 4 5 6 160 | 7 8 9 10 161 | 162 | Q21. 163 | 164 | 1 165 | 123 166 | 12345 167 | 1234567 168 | 123456789 169 | 170 | Q22. 171 | 172 | 1234554321 173 | 1234**4321 174 | 123****321 175 | 12******21 176 | 1********1 177 | 178 | Q23. 179 | 180 | 1 181 | 2 3 4 182 | 5 6 7 8 9 183 | 184 | Q24. 185 | 186 | 11111 187 | 2222 188 | 333 189 | 22 190 | 1 191 | 192 | Q25. 193 | 194 | 5432* 195 | 543*1 196 | 54*21 197 | 5*321 198 | *4321 199 | 200 | Q26. 201 | 202 | 1 203 | 121 204 | 12321 205 | 1234321 206 | 123454321 207 | 208 | Q27. 209 | 210 | 0 211 | 909 212 | 89098 213 | 7890987 214 | 678909876 215 | 56789098765 216 | 4567890987654 217 | 345678909876543 218 | 23456789098765432 219 | 1234567890987654321 220 | 221 | Q28. 222 | 223 | 1 1 224 | 12 21 225 | 123 321 226 | 1234 4321 227 | 1234554321 228 | 229 | Q29. 230 | 231 | 1 232 | 21 233 | 321 234 | 4321 235 | 54321 236 | 237 | Q30. 238 | 239 | 1 240 | 2*2 241 | 3*3*3 242 | 4*4*4*4 243 | 5*5*5*5*5 244 | 4*4*4*4 245 | 3*3*3 246 | 2*2 247 | 1 248 | 249 | Q31. 250 | 251 | 11 252 | 12 13 253 | 13 14 15 254 | 14 15 16 17 255 | 15 16 17 18 19 256 | 257 | Q32. 258 | 259 | 1 260 | 2 3 261 | 3 4 5 262 | 4 5 6 7 263 | 5 6 7 8 9 264 | 265 | Q33. 266 | 267 | 0 268 | 1 2 269 | 2 3 4 270 | 3 4 5 6 271 | 4 5 6 7 8 272 | 5 6 7 8 9 10 273 | 274 | Q34. 275 | 276 | 1 277 | 2 3 278 | 4 5 6 279 | 7 8 9 10 280 | 11 12 13 14 15 281 | 282 | Q35. 283 | 284 | 5 285 | 5 4 286 | 5 4 3 287 | 5 4 3 2 288 | 5 4 3 2 1 289 | 290 | Q36. 291 | 292 | 1 293 | 212 294 | 32123 295 | 4321234 296 | 543212345 297 | 298 | Q37. 299 | 300 | 1 2 3 4 5 301 | 6 7 8 9 302 | 10 11 12 303 | 13 14 304 | 15 305 | 306 | Q38. 307 | 308 | 12345 309 | 23451 310 | 34521 311 | 45321 312 | 54321 313 | 314 | Q39. 315 | 316 | 11111 317 | 0000 318 | 111 319 | 00 320 | 1 321 | 322 | Q40. 323 | 324 | 1 325 | 4 9 16 326 | 25 36 49 64 81 327 | 100 121 144 169 196 225 256 328 | 289 324 361 400 441 484 529 576 625 329 | 330 | Q41. 331 | 332 | 1 1 1 1 1 333 | 1 1 334 | 1 1 335 | 1 1 336 | 1 1 1 1 1 337 | 338 | Q42. 339 | 340 | 1 341 | 1 2 342 | 1 2 3 343 | 1 2 3 4 344 | 1 2 3 4 5 345 | 346 | Q43. 347 | 348 | 1 349 | 123 350 | 12345 351 | 1234567 352 | 123456789 353 | 1234567 354 | 12345 355 | 123 356 | 1 357 | 358 | Q44. 359 | 360 | *OOO*OOO* 361 | O*OO*OO*O 362 | OO*O*O*OO 363 | OOO***OOO 364 | 365 | Q45. 366 | 367 | 5 5 5 5 5 5 5 5 5 368 | 5 4 4 4 4 4 4 4 5 369 | 5 4 3 3 3 3 3 4 5 370 | 5 4 3 2 2 2 3 4 5 371 | 5 4 3 2 1 2 3 4 5 372 | 373 | Q46. 374 | 375 | 5 5 5 5 5 5 5 5 5 376 | 5 4 4 4 4 4 4 4 5 377 | 5 4 3 3 3 3 3 4 5 378 | 5 4 3 2 2 2 3 4 5 379 | 5 4 3 2 1 2 3 4 5 380 | 5 4 3 2 2 2 3 4 5 381 | 5 4 3 3 3 3 3 4 5 382 | 5 4 4 4 4 4 4 4 5 383 | 5 5 5 5 5 5 5 5 5 384 | 385 | Q47. 386 | 387 | 1 388 | 2 4 389 | 3 6 9 390 | 4 8 12 16 391 | 5 10 15 20 25 392 | 6 12 18 24 30 36 393 | 7 14 21 28 35 42 49 394 | 8 16 24 32 40 48 56 64 395 | 9 18 27 36 45 54 63 72 81 396 | 10 20 30 40 50 60 70 80 90 100 397 | 398 | Q48. 399 | 400 | 1 401 | 11 402 | 121 403 | 1331 404 | 14641 405 | 406 | Q49. 407 | 408 | 12345 409 | 21234 410 | 32123 411 | 43212 412 | 54321 413 | 414 | Q50. 415 | 416 | 1 417 | 3 2 418 | 4 5 6 419 | 10 9 8 7 420 | 11 12 13 14 15 421 | 422 | Q51. 423 | 424 | 1 425 | 232 426 | 34543 427 | 4567654 428 | 567898765 429 | 430 | Q52. 431 | 432 | 1 1 433 | 2 2 434 | 3 3 435 | 4 4 436 | 5 437 | 438 | Q53. 439 | 440 | 1 1 441 | 2 2 442 | 3 3 443 | 4 4 444 | 5 445 | 4 4 446 | 3 3 447 | 2 2 448 | 1 1 449 | 450 | Q54. 451 | 452 | 1 453 | 2 6 454 | 3 7 10 455 | 4 8 11 13 456 | 5 9 12 14 15 457 | 458 | Q55. 459 | 460 | 1 461 | 1 2 1 462 | 1 2 3 2 1 463 | 1 2 3 4 3 2 1 464 | 1 2 3 4 5 4 3 2 1 465 | 466 | Q56. 467 | 468 | 1 469 | 2 2 470 | 3 3 471 | 4 4 472 | 5 5 473 | 474 | Q57. 475 | 476 | 1 477 | 2 2 478 | 3 3 479 | 4 4 480 | 5 5 481 | 4 4 482 | 3 3 483 | 2 2 484 | 1 485 | 486 | Q58. 487 | 488 | 1 2 3 4 5 489 | 16 6 490 | 15 7 491 | 14 8 492 | 13 12 11 10 9 493 | 494 | Q59. 495 | 496 | 86523 497 | 8652 498 | 865 499 | 86 500 | 8 501 | 502 | Q60. 503 | 504 | 3 505 | 32 506 | 325 507 | 3256 508 | 32568 509 | 510 | Q61. 511 | 512 | 1 2 3 4 5 6 7 8 9 10 513 | 36 37 38 39 40 41 42 43 44 11 514 | 35 64 65 66 67 68 69 70 45 12 515 | 34 63 84 85 86 87 88 71 46 13 516 | 33 62 83 96 97 98 89 72 47 14 517 | 32 61 82 95 100 99 90 73 48 15 518 | 31 60 81 94 93 92 91 74 49 16 519 | 30 59 80 79 78 77 76 75 50 17 520 | 29 58 57 56 55 54 53 52 51 18 521 | 28 27 26 25 24 23 22 21 20 19 522 | 523 | Q62. 524 | 525 | 1 526 | 12 527 | 123 528 | 1234 529 | 12345 530 | 531 | Q63. 532 | 533 | 5 534 | 54 535 | 543 536 | 5432 537 | 54321 538 | 539 | Q64. 540 | 541 | 1 542 | 21 543 | 321 544 | 4321 545 | 54321 546 | 547 | Q65. 548 | 549 | 5 550 | 45 551 | 345 552 | 2345 553 | 12345 554 | 555 | 556 | All answers are already given. You can find them by their question number. 557 | 558 | Note--> if you know any pattern question which is not in this question set, please send me on my insta or twitter or linkedin. 559 | 560 | 561 | --------------------------------------------------------------------------------