Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <conio.h>
- #include <windows.h>
- #include <vector>
- #include <string>
- #include <math.h>
- using namespace std;
- void func1(int sys1, int sys2, string num);
- void func2(int sys1, int sys2, string num);
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "Их 13-ричной системы в 5-ричную: ";
- string num;
- getline(cin, num);
- cout << "С массивом: ";
- func1(13, 5, num);
- cout << '\n' << "Без массива: ";
- func2(13, 5, num);
- _getch();
- return 0;
- }
- void func1(int sys1, int sys2, string num) {
- int i, j;
- int vectsize = num.size();
- int dec = 0, count = 0;
- for (i = 0, j = vectsize - 1; i < vectsize - 1, j >= 0; i++, j--) {
- if ((num[j] - '0') >= 0 && (num[j] - '0') < 9) {
- dec += (num[j] - '0') * pow(sys1, i);
- count++;
- }
- else if (int(num[j]) >= 65 && int(num[j]) <= 90 && (num[j] - '7') < sys1) {
- dec += (num[j] - '7') * pow(sys1, i);
- count++;
- }
- else {
- cout << "Введите корректное число!";
- //return 0;
- }
- }
- char newnum[100] = "";
- i = 0;
- while (dec >= 1) {
- newnum[i] = dec % sys2 + '0';
- dec /= sys2;
- i++;
- }
- for (i - 1; i >= 0; i--) {
- cout << newnum[i];
- }
- }
- void func2(int sys1, int sys2, string num) {
- long long int des1 = 0, tr1 = 1;
- //cout << '\n' << "БЕЗ МАССИВОВ" << '\n' << "Введите число в тринадцатеричной системе: ";
- char chislo = ' ';
- int l = num.size();
- l = l - 1;
- //перевод в десятичную
- while (chislo != '\n') {
- chislo = getchar();
- if (chislo == '\n')
- break;
- else if (chislo <= '9')
- des1 += (chislo - '0') * pow(13, l);
- else
- des1 += (chislo - 'A' + 10) * pow(13, l);
- l--;
- }
- //перевод в троичную
- cout << "Пятиричное число: ";
- if (des1 == 0)
- cout << 0;
- else {
- while (tr1 <= des1) {
- tr1 *= 5;
- }
- while (tr1 > 1) {
- tr1 /= 5;
- if (des1 / tr1 < 10)
- cout << (des1 / tr1);
- else
- cout << (des1 / tr1) + 'A' - 10;
- des1 %= tr1;
- }
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement