Advertisement
ALTracer

lab5v9-working.cxx

Dec 23rd, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2. //#include <math.h>
  3. #include <locale.h>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. int pow (int base,int power) {
  9.     int r=1;
  10.     for(int i=0;i<power;i++){
  11.             r*=base;
  12.     }
  13.     return r;
  14. }
  15.  
  16. int main(int argc, char **argv){
  17.     setlocale(LC_ALL,"rus");
  18.     //short l = 3;
  19.     char a[9]="DEADBEEF"; // last symbol is line terminator '\0'
  20.     char b[9]="DEADBEEF";
  21.     float e;
  22.     float c=0; float d=0;
  23.  
  24.     cout << "Введите два числа: в восьмеричной от 0 до 777" << endl;
  25.     cout << "и в четверичной, от 0 до 333:" << endl;
  26.     cin >> a;
  27.     cin >> b;
  28.  
  29.     const char oct_alphabet[9] = "01234567";
  30.     const char four_alphabet[5] = "0123";
  31.     /**int dec_alphabet[8];
  32.     for(i=0;i<=7;i++) dec_alphabet[i]=i;**/
  33.  
  34.     short la=strlen(a);
  35.     for(short i=0;i<=la;i++){
  36.         for(short j=0;j<=7;j++){
  37.             //cout << i << j << a[la-i-1] << oct_alphabet[j] << endl;
  38.             if(a[la-i-1]==oct_alphabet[j]) c+=(j)*pow(8,i);
  39.         };
  40.     };
  41.     short lb=strlen(b);
  42.     for(short i=0;i<=lb;i++){
  43.         for(short j=0;j<=3;j++){
  44.             if(b[lb-i-1]==four_alphabet[j]) d+=(j)*pow(4,i);
  45.         };
  46.     };
  47.     e=c/d;
  48.     cout << "В десятичной, " << c <<  " разделить на " << d << " равно " << e <<endl;
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement