C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ 转换字符数程序

在C++语言中,我们可以借助循环和切换大小写轻松地转换字符中的数字。在此程序中,我们从用户那里获取输入并迭代该数字直到它为0。在迭代过程中,我们将其除以10,然后在切换的情况下传递其余部分以获取该数字的单词。
让我们看看C++程序如何将数字转换为字符。
#include <iostream>
using namespace std;
int main()
{
long int n,sum=0,r;  
cout<<"Enter the Number= ";  
cin>>n;  
while(n>0)  
{  
r=n%10;  
sum=sum*10+r;  
n=n/10;  
}  
n=sum;  
while(n>0)  
{  
r=n%10;  
switch(r)  
{  
case 1:  
cout<<"one ";  
break;  
case 2:  
cout<<"two ";  
break;  
case 3:  
cout<<"three ";
break;  
case 4:  
cout<<"four ";
break;  
case 5:  
cout<<"five ";
break;  
case 6:  
cout<<"six "; 
break;  
case 7:
cout<<"seven ";
break;
case 8:  
cout<<"eight ";  
break;  
case 9:  
cout<<"nine ";
break;  
case 0:  
cout<<"zero ";
break;  
default:  
cout<<"tttt ";  
break;  
}  
n=n/10;  
}  
}
输出:
Enter the Number= 74254
seven four two five four
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4