ChameL1oN

Лаба3_Задача2А

Dec 17th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ofstream B;
  6.  
  7. // Перевести число в систему P<10
  8. void func(int c, int w)
  9. {
  10. int n = 1, j = c;
  11. int b = 0;
  12. B << "Число в нужной системе счисления = ";
  13. while (c >= w){
  14. c /= w;
  15. }
  16. while (j >= w){
  17. b += j%w * n;
  18. j /= w;
  19. n *= 10;
  20. }
  21. b += c * n;
  22. cout << b;
  23. B << b;
  24. cout << endl;
  25. }
  26.  
  27. void main()
  28. {
  29. setlocale(LC_ALL, "rus");
  30. int a;
  31. int q;
  32. ifstream A;
  33. cout << "Введите нужную систему счисления";
  34. cin >> q;
  35. A.open("A.txt", ios::in);
  36. B.open("B.txt");
  37. while (!A.eof())
  38. {
  39. A >> a;
  40. B << "Начально число = " << a << " ";
  41.  
  42. func(a, q);
  43. B << " " << endl;
  44. }
  45.  
  46. A.close();
  47. B.close();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment