Posts

Showing posts from September, 2020

Pyramid Problem No. 93

  Q.93 Print positive-negative number triangle as: 9 8 6 7 5 3 4 2 0 -2 1 -1 -3 -5 -7 Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count_pos=9,count_neg=8; for(row=1; row<=n; row++){ for(col=1; col<=row; col++){ if(row%2==0) { printf("%3d ",count_neg); count_neg-=2; } else { printf("%3d ",count_pos); count_pos-=2; } } printf("\n"); } return 0; }

Pyramid Problem No. 89

  Q.89 Any number geometric sequence number pyramid as: 7 14 15 28 29 30 31 56 57 58 59 60 61 62 63 Solving in C : #include <stdio.h> #include<math.h> int main(){ int n=4,row,col,count; for(row=0; row<n; row++){ for(col=1,count=7*pow(2,row); col<=pow(2,row); col++) printf("%-3d",count++); printf("\n"); } return 0; }

Pyramid Problem No. 86

  Q.86 Design the following continues number pyramid: 1 121 12321 1234321 123454321 Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count=1; for(row=1; row<=n; row++){ for(col=1,count=1;col<=row; col++) printf("%d",count++); for(col=1,count=row-1; col<row; col++) printf("%d",count--); printf("\n"); } return 0; }

Pyramid Problem No. 85

  Q.85 Design the following number pyramid: 1 121 1231 12341 123451 Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count=1; for(row=1; row<=n; row++){ for(col=1,count=1;col<=row; col++) printf("%d",count++); if(row>1) printf("1"); printf("\n"); } return 0; }

Pyramid Problem No. 84

  Q.84 Print the following number design: 1 23 4 56 7 89 10 Solving in C: #include <stdio.h>     int main(){         int n=7,row,col,count=1;         for(row=1; row<=n; row++){             for(col=1;row%2==1 && col<=1; col++) printf("%d",count++);             for(col=1; row%2==0 && col<=2; col++) printf("%d",count++);                          printf("\n");         }         return 0;     }

Pyramid Problem No. 81

  Q.81 Print continue character number pyramid as: 1 A B 2 3 4 C D E F 5 6 7 8 9 Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count=1,count_alpha=65; for(row=1; row<=n; row++){ for(col=1;col<=row && row%2==1; col++) printf("%d ",count++); for(col=1;col<=row && row%2==0; col++) printf("%c ",count_alpha++); printf("\n"); } return 0; }

Pyramid Problem No. 77

  Q.77 Write the 1 and 0 number pyramid program as: 1 01 101 0101 10101 Solving in C: #include <stdio.h> int main(){ int n=5,row,col; for(row=1; row<=n; row++){ for(col=1;col<=row; col++){ if((row%2==0 && col%2==1) || (row%2==1 && col%2==0)) printf("0"); else printf("1"); } printf("\n"); } return 0; }

Pyramid Problem No. 76

  Q.76 Write a C program to print 0 and 1 number triangle as: 1 01 010 1010 10101 Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count=1; for(row=1; row<=n; row++){ for(col=1;col<=row; col++,count++) printf("%d",count%2); printf("\n"); } return 0; }

Pyramid Problem No. 75

  Q.75 Write a C program to print number character pyramid as: 1 a 21 ba 321 cba 4321 dcba 54321 edcba Solving in C: #include <stdio.h> int main(){ int n=5,row,col,count; for(row=1; row<=n; row++){ for(col=1,count=row; col<=row; col++,count--) printf("%d",count); for(col=1;col<=n-row;col++) printf(" "); printf("\t"); for(col=1,count=96+row; col<=row; col++) printf("%c",count--); printf("\n"); } return 0; }

Pyramid Problem No. 74

  Q.74 Write a C program to print the following number pyramid: 1333 2222 3331 Solving in C: #include <stdio.h> int main(){ int n=3,row,col,count; for(row=1; row<=n; row++){ for(col=1; col<=row; col++) printf("%d ",row); for(col=n-row+1,count=n-row+1; col>=1; col--) printf("%d ",count); printf("\n"); } return 0; }

Pyramid Problem No. 73

  Q.73 Write a C program to print the following number pyramid: 1 123 12345 1234567 Solving in C: #include <stdio.h> int main(){ int n=4,row,col; for(row=1; row<=n; row++){ for(col=1; col<=2*row-1; col++) printf("%d",col); printf("\n"); } return 0; }

Pyramid Problem No. 72

  Q.72 Write a C program to print the following number pyramid using function: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 Solving in C: #include <stdio.h> pattern_print(); int main(){ pattern_print(); return 0; } pattern_print(){ int n=5,row,col,count=1; for(row=1; row<=n; row++){ for(col=1; col<=row; col++) { if(count>9) count=1; printf("%d ",count++); } printf("\n"); } }

Pyramid Problem No. 69

  Q.69 Write a C program to print the following character rectangle program: ABCD BCDA CDAB DABC Solving in C: #include <stdio.h> int main(){ int n=4,row,col,prnt_alpa; for(row=1; row<=n; row++){ for(col=n-row+1,prnt_alpa=64+row; col>=1; col--,prnt_alpa++) printf("%c",prnt_alpa); for(col=1,prnt_alpa=65; col<=row-1; col++,prnt_alpa++) printf("%c",prnt_alpa); printf("\n"); } return 0; }

Pyramid Problem No. 68

  Q.68 Write a C program to print the following number rectangle program: 1234 2341 3412 4123 Solving iin C: #include <stdio.h> int main(){ int n=4,row,col,prnt; for(row=1; row<=n; row++){ for(col=n-row+1,prnt=row; col>=1; col--,prnt++) printf("%d",prnt); for(col=1,prnt=1; col<=row-1; col++,prnt++) printf("%d",prnt); printf("\n"); } return 0; }

Pyramid Problem No. 66

  Q.66 Write a C program to print the following character rectangle design: ABCBA AB BA A A AB BA ABCBA Solving in C: #include <stdio.h> int main(){ int row,col,count_1=1,print_Alpa; for(row=2; row>=1; row--){ for(col=1,print_Alpa=65; col<=2; col++,print_Alpa++) printf("%c",print_Alpa); for(col=1; col<=2*(2-row)-1; col++) printf(" ",col); for(col=row+1,print_Alpa=65+row; col>=1; col--,print_Alpa--) printf("%c",print_Alpa); printf("\n"); } for(row=1; row<=3; row++){ for(col=1,print_Alpa=65; col<=row; col++,print_Alpa++) printf("%c",print_Alpa); for(col=1; col<=2*(3-row)-1; col++) printf(" ",col); for(col=row,print_Alpa=64+row; col>=1; col--,print_Alpa--) { if(col==3 && row==3) cont...

Pyramid Problem No. 65

  Q.65 Write a C program to print the following number rectangle structure: 12321 12 21 1 1 12 21 12321 Solving in C: #include <stdio.h> int main(){ int row,col,count_1=1; for(row=2; row>=1; row--){ for(col=1; col<=2; col++) printf("%d",col); for(col=1; col<=2*(2-row)-1; col++) printf(" ",col); for(col=row+1; col>=1; col--) printf("%d",col); printf("\n"); } for(row=1; row<=3; row++){ for(col=1; col<=row; col++) printf("%d",col); for(col=1; col<=2*(3-row)-1; col++) printf(" ",col); for(col=row; col>=1; col--) { if(col==3 && row==3) continue; else printf("%d",col); } printf("\n"); } return 0; }

Pyramid Problem No. 83

  Q.83 Print any random number pyramid as: 4572 572 72 2 Solving in C: #include <stdio.h> int main(){     int n=4,row,col,count,skip_count;     for(row=n,skip_count=1; row>=1; row--,skip_count++){         for(col=1,count=n; col<=n; col++,count+=col-1){                          if(skip_count>col) continue;             else{                 if(col==n) printf("%d ",2);                 else printf("%d ",count);                 }         }         printf("\n");     }     return 0; }

Pyramid Problem No. 64

  Q.64 Write a C program to print the following number pyramid: 1 232 34543 4567654 Solving in C: #include <stdio.h> int main(){ int row,col,count_1=1; for(row=1; row<=4; row++,count_1--){ for(col=1,count_1=row; col<=row; col++)printf("%d",count_1++); for(col=1,count_1-=1; col<row; col++)printf("%d",--count_1); printf("\n"); } return 0; }

Pyramid Problem No. 61

  Q.61 Write a C program to print the following number pyramid: 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5 Solving in C: #include <stdio.h> int main(){ int row,col,row_count; for(row=1; row<=5; row++){ for(col=1; col<row; col++)printf(" "); for(col=5-row+1,row_count=row; col>=1; col--) printf("%d ",row_count++); printf("\n"); } return 0; }

Pyramid Problem No. 62

  Q.62 Write a C program to print the following character pyramid: A BA ABA BABA ABABA Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=1;col<=row; col++){ if((row%2==0 && col%2==1) || (row%2==1 && col%2==0)) printf("B"); else printf("A"); } printf("\n"); } return 0; }

Pyramid Problem No. 59

  Q.59 Write a C program to print the number character pyramid as: 1 AB 123 ABCD 12345 Solving in C: #include <stdio.h> int main(){ int row,col,ch_count; for(row=1; row<=5; row++){ for(col=1,ch_count=65; col<=row; col++){ if(row%2==0) printf("%c",ch_count++); else printf("%d",col); } printf("\n"); } return 0; }

Pyramid Problem No. 60

  Q. 60 Write a C program to print the following Floyd triangle as: 1 2 3 4 5 6 7 8 9 10 Solving in C: #include <stdio.h>     int main(){         int row,col,count=1;         for(row=4; row>=1; row--){             for(col=1; col<=row; col++) printf(" ");             for(col=1; col<=4-row+1; col++) printf("%d ",count++);             printf("\n");         }         return 0;     }

Pyramid Problem No. 58

  Q.58 Write a C program to print the following number pyramid/triangle: 54321 5432 543 54 5 Solving in C: #include <stdio.h> int main(){ int row,col,count; for(row=5; row>=1; row--){ for(col=1,count=5; col<=row; col++,count--) printf("%d",count); printf("\n"); } return 0; }

Pyramid Problem No. 57

  Q. 57 Write a C program to display odd number series pyramid as: 1 3 5 7 9 11 13 15 17 19 Solving in C: #include <stdio.h> int main(){ int row,col,row_count,count=1; for(row=1; row<=3; row++){ for(col=1,row_count+=row-1; col<=row+row_count; col++,count+=2) printf("%2d ",count); printf("\n"); } return 0; }

Pyramid Problem No. 53

  Q. 53 Write a C program to print the following rectangle number pyramid: 33333 32223 32123 32223 33333 Solving in C: #include<stdio.h> int main(){ int row,col; for(row=3; row>=1; row--){ for(col=3; col>=1; col--) { if(col<=row) printf("%d",row); else printf("%d",col); } for(col=2; col<=3; col++){ if((col<=row)) printf("%d",row); else printf("%d",col); } printf("\n"); } for(row=1; row<=3-1; row++){ for(col=3; col>=1; col--) { if(col<=row) printf("%d",row+1); else printf("%d",col); } for(col=2; col<=3; col++){ if(col<=row) printf("%d",row+1); else printf("%d",col); } printf("\n"); } return 0; }

Pyramid Problem No. 92

  Q.92 Print equilateral triangle number as: 5 454 34543 2345432 123454321 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=5; row>=1; row--){ for(col=1; col<=5; col++){ if(row>col) printf(" "); else printf("%d",col); } for(col=5-1; col>row-1; col--) printf("%d",col); printf("\n"); } return 0; }

Pyramid Problem No. 91

  Q.91 Print half-square number triangle as: 543212345 4321234 32123 212 1 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=5; col>=1; col--){ if(5-row+1<col) printf(" "); else printf("%d",col); } for(col=2; col<=5-row+1; col++) printf("%d",col); printf("\n"); } return 0; }

Pyramid Problem No. 90

  Q.90 Print the nested hash-star pyramid as: #####*##### ####*#*#### ###*###*### ##*#####*## #*#######*# *#########* Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=6; row++){ for(col=1; col<=11; col++){ if(col==(11/2+1)+1-row || col==(11/2)+row) printf("*"); else printf("#"); } printf("\n"); } return 0; }

Pyramid Problem No. 88

  Q.88 print diagonal star-zero pyramid as: *000000 0*00000 00*0000 000*000 0000*00 00000*0 000000* Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=7; row++){ for(col=1; col<=7; col++){ if(row==col) printf("*"); else printf("0"); } printf("\n"); } return 0; }

Pyramid Problem No. 87

  Q.87 Print following alternative number-star pyramid as: 1 2*2 3*3*3 4*4*4*4 4*4*4*4 3*3*3 2*2 1 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=4; row++){ for(col=1; col<=2*row-1; col++){ if(col%2==0) printf("*"); else printf("%d",row); } printf("\n"); } for(row=4; row>=1; row--){ for(col=1; col<=2*row-1; col++){ if(col%2==0) printf("*"); else printf("%d",row); } printf("\n"); } return 0; }

Pyramid Problem No. 82

  Q.82 Print below nested star pyramid as: * *** *** * ** ** ** ** *** * * *** Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=3; row++){ for(col=1;col<=11; col++){ if(col==11/2+1 || col==row+1 || col==11-row) printf(" "); else printf("*"); } printf("\n"); } return 0; }

Pyramid Problem No. 80

  Q.80 Even-odd number star pyramid as: 1 *2 1*3 *2*4 1*3*5 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=1;col<=row; col++){ if((row%2==0 && col%2==1) || (row%2==1 && col%2==0)) printf("*"); else printf("%d",col); } printf("\n"); } return 0; }

Pyramid Problem No. 79

  Q.79 Print Rectangle star pyramid as: ****** * * * * ****** Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=4; row++){ for(col=1;col<=6; col++){ if(row==1 || col==1 || row==4 || col==6) printf("*"); else printf(" "); } printf("\n"); } return 0; }

Pyramid Problem No. 78

Q.78 Print Square star pyramid as: ***** *    * *      * ***** Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=4; row++){ for(col=1;col<=7; col++){ if(row==1 || col==1 || row==4 || col==7) { if((row==1 && col==1) || (row==1 && col==7) || (row==4 && col==1) || (row==4 && col==7) ) printf(" "); else printf("*"); } else printf(" "); } printf("\n"); } return 0; }

Pyramid Problem No. 67

  Q.67 Write a C program to print the following star triangle structure: ********* ******* ***** *** * Solving in C: #include <stdio.h> int main(){ int row,col; for(row=5; row>=1; row--){ for(col=2*row-1;col>=1; col--) printf("*"); printf("\n"); } return 0; }

Pyramid Problem No. 63

  Q.63 Write a C program to accept the number of rows of pyramid and print the star pyramid as:if entered number by user is 7 then output would be: * ** *** **** *** ** * Solving in C: #include <stdio.h> int main(){ int row,col,row_count; for(row=1,row_count=7; row<=7; row++,row_count--){ //user entered 7 ,that's why row 7 for(col=1; row<=(7/2.0)+1 && col<=row; col++) printf("*"); for(col=row_count; row>(7/2.0)+1 && col>=1; col--) printf("*"); printf("\n"); } return 0; }

Pyramid Problem No. 56

  Q. 56 Write a C program to display the reverse star pyramid as: ********** **** **** *** *** ** ** * * Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=1; col<=5-row+1; col++) printf("*"); for(col=1; col<2*row-1; col++) printf(" "); for(col=1; col<=5-row+1; col++) printf("*"); printf("\n"); } return 0; }

Pyramid Problem No. 55

  Q. 55 Write a C program to print the following star pattern pyramid: * *** ****** Solving in C: #include <stdio.h> int main(){ int row,col,row_count=0; for(row=1; row<=3; row++){ for(col=1,row_count+=row-1; col<=row+row_count; col++) printf("*"); printf("\n"); } return 0; }

Pyramid Problem No. 54

  Q. 54 Write a C program to print the star triangle frame pyramid like as: * ** * * * * * * * * * * * * * * ********** Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=10; row++){ for(col=1; col<=row; col++){ if(col==row || col==1 || row==10)printf("*"); else printf(" "); } printf("\n"); } return 0; }

Pyramid Problem No. 52

  Q. 52 Write a C program to print the following star structure/fashion: ********* ******* ***** *** * *** ***** ******* ********* Solving in C: #include <stdio.h> int main(){ int row,col; for(row=5; row>=1; row--){ for(col=1; col<=5-row; col++) printf(" "); for(col=1; col<=2*row-1; col++) printf("*"); printf("\n"); } for(row=1; row<=5; row++){ for(col=1; col<=5-row; col++) printf(" "); for(col=1; col<=2*row-1; col++) printf("*"); printf("\n"); } return 0; }

Pyramid Problem No. 51

 Q. 51 Write a C program to print the following number triangle: 5 454 34543 2345432 123454321 Solving in C: #include <stdio.h>     int main(){         int row,col,count;          for(row=5; row>=1; row--){             for(col=1,count=row; col<=5-row+1; col++) printf("%d",count++);             for(col=1,count-=1; col<=5-row; col++) printf("%d",--count);             printf("\n");         }         return 0;     }

Pyramid Problem No. 50

  Q. 50 Write a C program to print the following number triangle: 5 45 345 2345 12345 Solving in C: #include <stdio.h> int main(){ int row,col,count; for(row=1; row<=5; row++){ for(col=1,count=5-row+1; col<=row; col++) printf("%d",count++); printf("\n"); } return 0; }

Pyramid Problem No. 49

  Q. 49 Write a C program to print the following number triangle: 9 898 78987 6789876 Solving in C: #include <stdio.h> int main(){ int row,col,count; for(row=1; row<=4; row++){ for(col=1,count=9-row+1; col<=row; col++,count++) printf("%d",count); for(col=1,count=9-1; col<=row-1; col++,count--) printf("%d",count); printf("\n"); } return 0; }

Pyramid Problem No. 48

  Q. 48 Write a C program to print the following number pyramid: 1 222 33333 4444444 555555555 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=1; row<=5; row++){ for(col=1; col<=5-row; col++) printf(" ",col); for(col=1; col<=2*row-1; col++) printf("%d ",row); printf("\n"); } return 0; }

Pyramid Problem No. 47

  Q. 47 Write a C program for print the following character pyramid: ABCDEFFEDCBA ABCDEEDCBA ABCDDCBA ABCCBA ABBA AA Solving in C: #include <stdio.h> int main(){ int row,col,ch; for(row=6; row>=1; row--){ for(col=1,ch=65; col<=row; col++,ch++) printf("%c",ch); for(col=row,ch=65+row-1; col>=1; col--,ch--) printf("%c",ch); printf("\n"); } return 0; }

Pyramid Problem No. 46

  Q. 46 Write a C program for print the following number pyramid: 123456654321 1234554321 12344321 123321 1221 11 Solving in C: #include <stdio.h> int main(){ int row,col; for(row=6; row>=1; row--){ for(col=1; col<=row; col++) printf("%d",col); for(col=row; col>=1; col--) printf("%d",col); printf("\n"); } return 0; }