Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     scanf("%d", &n);
  8.     int rowNeed = 0;
  9.     int colNeed = 0;
  10.     int i;
  11.  
  12.     // get number of coll.
  13.     for(i=n; i>1; i--){
  14.         colNeed ++;
  15.     }
  16.     colNeed = colNeed*2;
  17.     colNeed ++;
  18.  
  19.     // the row and the col. number is tha same in every case
  20.  
  21.     rowNeed = colNeed;
  22.  
  23.  
  24.     //print
  25.  
  26.     int col, row;
  27.     int mid = colNeed/2;
  28.     int hat = n;
  29.     int ir;
  30.     int f;
  31.     int d;
  32.  
  33.  
  34.     for(row=0; row<rowNeed; row++){
  35.         ir = n;
  36.         f=-1;
  37.         d=0;
  38.         for(col=0; col<colNeed; col++){
  39.             if(col<=mid){
  40.                 if(ir>hat){
  41.                     printf("%d ", ir);
  42.                     ir -= 1;
  43.                 }
  44.                 else if(ir==hat){
  45.                     printf("%d ", hat);
  46.                     f++;
  47.                 }
  48.             }
  49.             else if(col>mid){
  50.                 if(d<f){
  51.                     printf("%d ", hat);
  52.                     d++;
  53.                 }
  54.                 else{
  55.                     ir++;
  56.                     printf("%d ",ir);
  57.                 }
  58.             }
  59.  
  60.         }
  61.         if(row<mid){
  62.             hat--;
  63.         }
  64.         else{
  65.             hat++;
  66.         }
  67.  
  68.         printf("\n");
  69.     }
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement