Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <math.h>
- #include <locale.h>
- #include <string.h>
- using namespace std;
- int pow (int base,int power) {
- int r=1;
- for(int i=0;i<power;i++){
- r*=base;
- }
- return r;
- }
- int main(int argc, char **argv){
- setlocale(LC_ALL,"rus");
- //short l = 3;
- char a[9]="DEADBEEF"; // last symbol is line terminator '\0'
- char b[9]="DEADBEEF";
- float e;
- float c=0; float d=0;
- cout << "Введите два числа: в восьмеричной от 0 до 777" << endl;
- cout << "и в четверичной, от 0 до 333:" << endl;
- cin >> a;
- cin >> b;
- const char oct_alphabet[9] = "01234567";
- const char four_alphabet[5] = "0123";
- /**int dec_alphabet[8];
- for(i=0;i<=7;i++) dec_alphabet[i]=i;**/
- short la=strlen(a);
- for(short i=0;i<=la;i++){
- for(short j=0;j<=7;j++){
- //cout << i << j << a[la-i-1] << oct_alphabet[j] << endl;
- if(a[la-i-1]==oct_alphabet[j]) c+=(j)*pow(8,i);
- };
- };
- short lb=strlen(b);
- for(short i=0;i<=lb;i++){
- for(short j=0;j<=3;j++){
- if(b[lb-i-1]==four_alphabet[j]) d+=(j)*pow(4,i);
- };
- };
- e=c/d;
- cout << "В десятичной, " << c << " разделить на " << d << " равно " << e <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement