Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void dziel(int a, int b){
  7.     int w;
  8.     vector<int> v;
  9.     vector<int> tmp;
  10.     cout << a << " / " << b << " = "  ;
  11.  
  12.     cout << a/b << ",";
  13.     if(a>=b){
  14.         a =a%b;
  15.     }
  16.  
  17.     int r =a;
  18.     tmp.push_back(r);
  19.  
  20.     bool wystepuje = false;
  21.     int k;
  22.     do{
  23.         r=r*10;
  24.         w= r/b;
  25.         v.push_back(w);
  26.         r=r - b*w;
  27.         //SPRAWDZ CZY r WYSTEPUJE W WEKTORZE v
  28.         for(int i=0; i<tmp.size(); i++){
  29.             if(tmp[i]==r){
  30.                 k = i;
  31.                 wystepuje = true;
  32.                 break;
  33.             }
  34.         }
  35.         tmp.push_back(r);
  36.     }while(!wystepuje and r!=0);
  37. //    if(r!=0){
  38. //        cout << "(";
  39. //    }
  40.     for(int i =0; i< v.size(); i++){
  41.         if (i==k and r!=0){
  42.             cout << "(";
  43.         }
  44.         cout << v[i];
  45.     }
  46.  
  47.     if(r!=0){
  48.         cout << ")";
  49.     }
  50.  
  51.     cout << endl;
  52. }
  53.  
  54. int main()
  55. {
  56. //    int a= 123;
  57. //    int b= 7112;
  58.  
  59.     for(int a=1000; a<1004; a++)
  60.         for(int b= 1000; b<1004; b++)
  61.             dziel(a,b);
  62.  
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement