Saturday, June 19, 2021
Home coding Write a program to convert number in characters.

# Write a program to convert number in characters.

Given a number we have to convert them into character.

so what is character?

character are english letters like A,B,C,D . so we have to convert their numeric value to english alphabet.

for example-1 as one , 2 as two 3 as three.

Example:

``````input:18
output:one eight

input:23
output:two three``````

logic :

``divide a number by 10 and get the result and map them with english alphabet.``

```#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"enter a number: "<<endl;
cin>>num;
int sum=0;
int rem=0;
while(num>0)
{
rem=num%10;
sum=sum*10+rem;
num=num/10;
}
num=sum;
while(num>0)
{

rem=num%10;

switch(rem)
{

case 0:
cout<<"zero ";
break;

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;

default:

cout<<"number is not exist";
break;
}
num=num/10;
}
}  ```

Output:

```enter a number: 92
nine two ```

Time Complexity: O(N)

Space Complexity:O(1)

- Advertisment -