Advertisement
ALTracer

lab5v9

Dec 20th, 2018
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*
  2.  * lab5v9.cxx
  3.  *
  4.  * Copyright 2018 Денис <altracer@AspireE15>
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19.  * MA 02110-1301, USA.
  20.  *
  21.  *
  22.  */
  23.  
  24. #include <iostream>
  25. #include <math.h>
  26. #include <locale.h>
  27. using namespace std;
  28.  
  29. int main(int argc, char **argv)
  30. {
  31.     //setlocale(LC_ALL,"ru_RU.ISO-8859-5");
  32.     short l = 3;
  33.     char a[l+1]; // last symbol is line terminator '\0'
  34.     char b[l+1];
  35.     float e;
  36.     short i,j,c,d;
  37.     cout << "Введите два числа: в восьмеричной от 000 до 777" << endl;
  38.     cout << "и в четверичной, от 000 до 333:" << endl;
  39.     cin >> a;
  40.     cin >> b;
  41.    
  42.     const char oct_alphabet[9] = "01234567";
  43.     const char four_alphabet[5] = "0123";
  44.     int dec_alphabet[8];
  45.     for(i=0;i<=7;i++) dec_alphabet[i]=i;
  46.    
  47.     for(i=0;i<=l-1;i++){
  48.         for(j=0;j<=7;j++){
  49.             if(a[l-1-i]==oct_alphabet[j]) c+=dec_alphabet[j]*pow(8,i);
  50.         };
  51.     };
  52.    
  53.     for(i=0;i<=l-1;i++){
  54.         for(j=0;j<=3;j++){
  55.             if(b[l-1-i]==four_alphabet[j]) d+=dec_alphabet[j]*pow(4,i);
  56.         };
  57.     };
  58.     e=c/d;
  59.     cout << c <<endl;
  60.     cout << d <<endl;
  61.     cout << e <<endl;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement