编程题:八进制转换为十进制
输入一个八进制数: 116 八进制数 116 转换为十进制为 78
#include <stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int main(void) { int n[50], t = 0, sum = 0; int num, num1;
puts("请输入一个八进制数"); scanf("%d", &num); num1 = num; while (num > 0) { n[t] = num % 10; num /= 10; t++; } for (int i = 0; i < t; i++) { sum += n[i] * pow(8, i); } puts("十进制(8->10)"); printf("%d->%d", num1, sum);
return 0; }
#include<iostream>
#include<cmath>
using namespace std;
long long transformFromOctalToDecimal(long long Octal)
{
static int index=0;
if(Octal==0)
index=0;
return 0;
}
long long temporary=Octal%10*pow(8,index++);
return temporary+transformFromOctalToDecimal(Octal/10);
int main()
long long Octal;
cout<<"OctalNumber"<<endl;
cin>>Octal;
cout<<"DecimalNumber"<<endl;
cout<<transformFromOctalToDecimal(Octal)<<endl;
#include <stdi...
用户登录可进行刷题及查看答案
#include <stdio.h> #include <math.h> long long convertOctalToDecimal(int octalNumber); int main() { int octalNumber; printf("输入一个八进制数: "); scanf("%d", &octalNumber); printf("八进制数 %d 转换为十进制为 %lld", octalNumber, convertOctalToDecimal(octalNumber)); return 0; } long long convertOctalToDecimal(int octalNumber) { int decimalNumber = 0, i = 0; while(octalNumber != 0) { decimalNumber += (octalNumber%10) * pow(8,i); ++i; octalNumber/=10; } i = 1; return decimalNumber; }
登录后提交答案