c编程:将非十进制数字系统转换为十进制的程序 [英] c programming: program to convert non decimal number system to decimal

查看:100
本文介绍了c编程:将非十进制数字系统转换为十进制的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void main()
{
 long n,dec,mult,r,base;
 clrscr();
 printf("\n Enter a base : ");
 scanf("%ld",&base);
 printf("\n Enter a number :");
 scanf("%ld",&n);
 dec = 0;
 mult=1;
 printf("\n Decimal equivalent of base %ld number %ld is ",base,n);
 while ( n != 0 )
 {
  r = n % 10;
  n /= 10;
  r = r * mult;
  dec = dec + r;
  mult *= base;
 } 
 printf("%ld",dec);}


此程序将以2、8和16为基数的任何数字系统的整数部分转换为十进制.请告诉我命令shld b给定2还要计算小数部分.我急需它帮助.


this program converts the integer part of any number system of base 2, 8 &16 to decimal. please tell me wht command shld b given 2 calculate the fractional part also. i need it urgently plz help.

推荐答案

小数点右边的每个数字都是该基数的幂的倒数.因此,对于八进制数字,值0.44等于
Each digit to the right of the decimal point is the reciprocal of the power of the base for that base. So for octal numbers the value 0.44 equates to
0
4 / 8  // .4
4 /64  // . 04


这篇关于c编程:将非十进制数字系统转换为十进制的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆