In this tutorial you will learn about the C Program to Convert Number into Word and its application with practical example.
C Program to Convert Number into Word
In this tutorial, we will learn to create a C program that will convert Number into Word using C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- While loop in c programming.
- Switch Case statement in C Programming.
- Header Libraries and its usage.
Convert Number into Word
In c programming it is possible to take numerical input from the user and convert it into words with the help of very small amount of code . The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.
With the help of this program we can Convert Number into Word.
Algorithm:-
1 2 3 4 5 6 |
1. Declaring the variables for the program. 2. Taking the input number from the user. 3. Converting the given number to digits separately. 4. Passing those digits to while loop. 5. Using the switch case for converting the numbers to the digits one by one. 6. Printing the result words. |
Program to convert Number into Word:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include<stdio.h> #include<stdlib.h> int main() { //declaring the local variables for program long int no,sum=0,r; //taking number from user as a input to convert is to words printf("enter the number="); scanf("%ld",&no); //Converting to digits separately from a single big number while(no>0) { r=no%10; sum=sum*10+r; no=no/10; } no=sum; while(no>0) { r=no%10; //Converting to words from number switch(r) { case 1: printf("one "); break; case 2: printf("two "); break; case 3: printf("three "); break; case 4: printf("four "); break; case 5: printf("five "); break; case 6: printf("six "); break; case 7: printf("seven "); break; case 8: printf("eight "); break; case 9: printf("nine "); break; case 0: printf("zero "); break; default: printf("tttt"); break; } no=no/10; } return 0; } |
Output:-
The above program we have first initialize the required variable.
- no = it will hold the integer value.
- r = it will hold the value of digit.
- sum = it will hold the sum.
Including the header files required for program.
Input number from user.
Switch Case body.