C 練習(xí)實(shí)例82
題目:八進(jìn)制轉(zhuǎn)換為十進(jìn)制
程序分析:無(wú)。
程序源代碼:
// Created by www.15014759268.cn on 15/11/9. // Copyright © 2015年 W3Cschool教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> int main() { int n=0,i=0; char s[20]; printf("請(qǐng)輸入一個(gè)8進(jìn)制數(shù):\n"); gets(s); while(s[i]!='\0'){ n=n*8+s[i]-'0'; i++; } printf("剛輸入的8進(jìn)制數(shù)轉(zhuǎn)化為十進(jìn)制為\n%d\n",n); return 0; }
以上實(shí)例運(yùn)行輸出結(jié)果為:
請(qǐng)輸入一個(gè)8進(jìn)制數(shù): 16 剛輸入的8進(jìn)制數(shù)轉(zhuǎn)化為十進(jìn)制為 14
更多建議: