您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

将数字转换为单词的 C# 程序

2024/3/17 0:51:59发布15次查看
首先,声明从 0 到 9 的单词 -
// words for every digits from 0 to 9string[] digits_words = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
以下是要转换为单词的数字 -
// number to be converted into wordsval = 4677;console.writeline("number: " + val);
使用循环检查给定数字中的每个数字并将其转换为单词 -
do { next = val % 10; a[num_digits] = next; num_digits++; val = val / 10;} while(val > 0);
示例您可以尝试运行以下代码将数字转换为单词。
现场演示
using system;using system.collections.generic;using system.text;namespace demo { class myapplication { static void main(string[] args) { int val, next, num_digits; int[] a = new int[10]; // words for every digits from 0 to 9 string[] digits_words = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; // number to be converted into words val = 4677; console.writeline("number: " + val); console.write("number (words): "); next = 0; num_digits = 0; do { next = val % 10; a[num_digits] = next; num_digits++; val = val / 10; } while (val > 0); num_digits--; for (; num_digits >= 0; num_digits--) console.write(digits_words[a[num_digits]] + " "); console.readline(); } }}
输出number: 4677number (words): four six seven seven
以上就是将数字转换为单词的 c# 程序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product