Posts

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; }