How to write a C Program to Convert Number to words in C Programming Language ?
Solution:
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- printf("This program will write a integer number in words\n\n(Try to) keep the number less than 10000\n");
- int number,i,m,j,temp;
- char string[2][9];
- char ekok[9][6];
- int ara[10];
- printf("Write a number: (0) to exit ");
- scanf("%d", &number);
- while (number>0) {
- for(i=0; number!=0; i++){
- ara[i]=number%10;
- number=number/10;
- }
- m=i;
- for(i=i-1; i>=2; i--) {
- if(ara[i]==1) {
- printf("One ");
- }
- else if(ara[i]==2) {
- printf("Two ");
- }
- else if(ara[i]==3) {
- printf("Three ");
- }
- else if(ara[i]==4) {
- printf("Four ");
- }
- else if(ara[i]==5) {
- printf("Five ");
- }
- else if(ara[i]==6) {
- printf("Six ");
- }
- else if(ara[i]==7) {
- printf("Seven ");
- }
- else if(ara[i]==8) {
- printf("Eight ");
- }
- else if(ara[i]==9) {
- printf("Nine ");
- }
- if(i==2 && ara[i]!=0) {
- printf("Hundred ");
- }
- else if (i==3) {
- printf("Thousand ");
- }
- }
- while(i==1){
- if(ara[i]==0) {
- printf("");
- }
- else if(ara[i]==1) {
- if(ara[i-1]==0) {
- printf("Ten");
- i--;
- break;
- }
- else if(ara[i-1]==1) {
- printf("Eleven");
- i--;
- break;
- }
- else if(ara[i-1]==2) {
- printf("Twelve");
- i--;
- break;
- }
- else if(ara[i-1]==3) {
- printf("Thirteen");
- i--;
- break;
- }
- else if(ara[i-1]==4) {
- printf("Fourteen");
- i--;
- break;
- }
- else if(ara[i-1]==5) {
- printf("Fifteen");
- i--;
- break;
- }
- else if(ara[i-1]==6) {
- printf("Sixteen");
- i--;
- break;
- }
- else if(ara[i-1]==7) {
- printf("Seventeen");
- i--;
- break;
- }
- else if(ara[i-1]==8) {
- printf("Eighteen");
- i--;
- break;
- }
- else if(ara[i-1]==9) {
- printf("Nineteen");
- i--;
- break;
- }
- }
- else if(ara[i]==2) {
- printf("Twenty ");
- }
- else if(ara[i]==3) {
- printf("Thirty ");
- }
- else if(ara[i]==4) {
- printf("Fourty ");
- }
- else if(ara[i]==5) {
- printf("Fifty ");
- }
- else if(ara[i]==6) {
- printf("Sixty ");
- }
- else if(ara[i]==7) {
- printf("Seventy ");
- }
- else if(ara[i]==8) {
- printf("Eighty ");
- }
- else if(ara[i]==9) {
- printf("Ninety ");
- }
- i--;
- }
- if(ara[i+1]!=1 || m==1) {
- if(ara[i]==0) {
- printf("");
- }
- else if(ara[i]==1) {
- printf("One");
- }
- else if(ara[i]==2) {
- printf("Two");
- }
- else if(ara[i]==3) {
- printf("Three");
- }
- else if(ara[i]==4) {
- printf("Four");
- }
- else if(ara[i]==5) {
- printf("Five");
- }
- else if(ara[i]==6) {
- printf("Six");
- }
- else if(ara[i]==7) {
- printf("Seven");
- }
- else if(ara[i]==8) {
- printf("Eight");
- }
- else if(ara[i]==9) {
- printf("Nine");
- }
- }
- printf("\n");
- printf("\nWrite a number: (0) to exit ");
- scanf("%d", &number);
- }
- }
Learn More :
Number
- Find out the perfect number using c program
- Write a c program to find out H.C.F. of two numbers.
- Check the given number is armstrong number or not using c program.
- Write a c program to find largest among three numbers using conditional operator
- FIND OUT GENERIC ROOT OF A NUMBER - C PROGRAM.
- FIND PRIME FACTORS OF A NUMBER USING C PROGRAM
- How To Write a C program that generates two random numbers ?
- Write a C program to find maximum or equal between two numbers ?
- How to Write a C program to find maximum between two numbers ?
- Write a C program to perform math operations on two input whole numbers. The operations are:
- Write a C program to find maximum between three numbers ?
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program to Enter an ODD number between 1 and 49.
- C program acquires keyboard 10 numbers for each of these numbers to determine if it is a first issue, by printing immediately message should at the end, if none of the numbers you entered was a first issue, print an appropriate message.
- C program generates a random number and uses an algorithm to generate 9 other numbers.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Reverse Of Any Digit Number
- C Program To Find The Frequency Of A Number
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print Sum Of n Digit Number
- C Program To Reverse A Number
- C Program To Search A Number Inside The Array
Convert
- How To Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.
- C Program to Convert Text String to Binary
- C Program To Convert Decimal To Binary Using Recursion
- C Program To Convert Temperature In Celsius To Fahrenheit, Using Function
- C Program To Convert Temperature Into Celsius
- C Program to Convert Celsius to Fahrenheit temperature
- C Program to convert a string to upper case
- C Program Convert MIDI note to pitch
- C Program to Convert Celcius to Fahrenheit and vice versa
- C Program to Convert a Decimal number to Octal Number
- C Program to Converts a Number to a String.
- C Program to Convert Celsius Temperature into Fahrenheit Temperature
- C Program to Recursively converts all file-names to lower-case
- C Program to accept string from user & convert all lower case letters into upper case letters & vice versa
- C Program to convert given decimal number into binary number
- C Program To Read The Adjecancy Matrix of Directed Graph And Convert It Into Adjecancy List