chillurbrain

8. Заполнение диагоналями.

May 21st, 2016
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int f,n,m,a[300][300];
  4. void rec(int x, int y)
  5. {
  6.     if(x<1 || y<1 || x>n || y>m)
  7.         return;
  8.     a[x][y]=f;
  9.     ++f;
  10.     rec(x+1,y-1);
  11. }
  12. int main()
  13. {
  14.     int i,j;
  15.     cin>>n>>m;
  16.     for(i=1;i<=m;++i)
  17.         rec(1,i);
  18.     for(i=2;i<=n;++i)
  19.         rec(i,m);
  20.     for(i=1;i<=n;++i)
  21.     {
  22.         for(j=1;j<=m;++j)
  23.             cout<<a[i][j]<<" ";
  24.         cout<<endl;
  25.     }
  26.     return 0;
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment