CS203数据结构和算法 [英] cs203 data structure and algorithm

查看:104
本文介绍了CS203数据结构和算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建从一个基数到另一个基数的基数转换器计算器
使用C#代码?

这是老师给的算法.

方法(基数转换器)

要基数(int decimalvalue,int radix)
返回类型:字符串
将十进制转换为任何基数(base,2,8,16)

到小数(字符串基数值,从基数起整数)
返回类型:int
将基数值(从任何基数)转换为十进制

然后在主程序中:

How can I create a radix converter calculator from one radix to another
using c# code?

Here''s the algorithm given by the teacher.

Methods(radix converter)

To radix(int decimalvalue, int radix)
return type : string
Convert Decimal to any radix(base,2,8,16)

To decimal(string radixvalue, int fromradix)
return type : int
Convert radixvalue(from any base)to decimal

Then in the main program:

main(string[] args)
return type : void
accepts input
(like thisone ...

 string userinput =Console.ReadLine();
 char[]array  = userinput.ToCharArray();
  foreach(char  val in array )
  { Console.WriteLine(val);

  }

推荐答案

而不是使用char数组,而是将用户输入转换为数字:查看 decimal.Parse [
Rather than playing with char arrays, convert your user input into numbers: Look at the Convert.ToDecimal[^] and decimal.Parse[^] methods instead. From there, you should be able to get started on your task!


这篇关于CS203数据结构和算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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