Advertisement
Lisaveta777

?

Oct 25th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 10
  3.  
  4. //работает, но куча вопросов (почему двойка последняя?
  5. //почему без последнего елсе не работает как надо?
  6. //остальные вроде помечены вопросы
  7.  
  8. int main()
  9. {
  10.  
  11.     int i,j,n,y,arr[N][2*N-1] = {0};
  12.     int curr, left, right;//pseudonames for array elements
  13.     char ch = '#';
  14.     y = 5;
  15.  
  16.     printf("%d\n",(y>10)? (y>3)? 1:10:100);//100 second,not ok!
  17.     printf("%d\n",(y<10)? (y>3)? 1:10:100);//1   first ok
  18.     printf("%d\n",(y>10)? (y<3)? 1:10:100);//100 third ok
  19.  
  20.  
  21.  
  22.     arr[0][N-1]=1;//fillling first row
  23.     arr[1][N-2]=arr[1][N]=1;//filling second row
  24.  
  25.      for(i=2;i<N;i++)
  26.     {
  27.         for(j=0;j<2*N-1;j++)
  28.         {
  29.             left  = arr[i-1][j-1];
  30.             right = arr[i-1][j+1];
  31.  
  32.             if(left && right)
  33.                 curr = left + right;
  34.             else if(left)
  35.                 curr = left;//is it better to use "curr = 1" here?
  36.             else if(right)
  37.                 curr = right;
  38.             else
  39.                 curr = 0;
  40.  
  41.             arr[i][j] = curr;//puts current value into array element
  42.             if(i==9&&j==9)
  43.                 printf("%d 9&&9\n\n",arr[i][j]);
  44.         }
  45.     }
  46.  
  47.     for(i =0;i<N;i++)
  48.     {
  49.         for(j=0;j<2*N-1;j++)
  50.         {
  51.             if(arr[i][j])
  52.                printf("%4d",arr[i][j]);
  53.             else
  54.                 printf("    ");
  55.  
  56.  
  57.         }
  58.  
  59.         //putchar( (arr[i][j])? arr[i][j] :' ');
  60.         //printf("%4s",(arr[i][j])? (char *) arr[i][j] : "    " );
  61.         //printf("%*c\n",ch);
  62.         printf("\n");
  63.     }
  64.  
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement