Advertisement
icatalin

trecere din baza 10 in baza b TEST 1

Oct 1st, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("date.in");
  7. ofstream g("date.out");
  8.  
  9. int main()
  10. {
  11.     int a[100][100],i,j,n,b,x,nr;
  12.     f>>n>>b;
  13.     for (i=1;i<=n;i++)
  14.     for (j=1;j<=n;j++)
  15.     {f>>a[i][j];
  16.     if (i==j)
  17.     {
  18.         nr=0;
  19.         x=a[i][j];
  20.         while (x)
  21.         {
  22.             nr=nr*10+x%b;
  23.             x=x/b;
  24.         }
  25.         a[i][j]=nr;
  26.  
  27.     }
  28.     }
  29.  
  30.     for (i=1;i<=n;i++)
  31.     {for (j=1;j<=n;j++)
  32.     g<<a[i][j]<<" ";
  33.     g<<'\n';
  34.     }
  35.  
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement