In this tutorial you will learn about the C Program to Print Number in Words and its application with practical example.
C Program to Print Number in Words.
In this tutorial, we will learn to create a C program that will Print Numbers in Words in 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 in
Print Numbers in Words
As we all know the c programming is a very powerful language. In the c programming language, we have many pre-defined functions for arithmetic operations. but today we will take the input number and Print Number in Words with the help of the c programming language.
With the help of this program, we can Print Numbers in Words.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declare the variables for the program. 2. Take the input number from the user. 3. Pass that number to a condition. 4. Print the output string after checking. 5. End the program. |
Program to Print Numbers in Words:-
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 65 66 67 68 |
/** * C program to print number in words */ #include <stdio.h> int main() { //declaring variables for the program int no, num = 0; /* Input number from user */ printf("Enter any number to print in words: "); scanf("%d", &no); /* Store reverse of n in num */ while(no != 0) { num = (num * 10) + (no % 10); no /= 10; } /* * Extract last digit of number and print corresponding digit in words * till num becomes 0 */ while(num != 0) { switch(num % 10) { //printing the digits in words case 0: printf("Zero "); break; 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; } num = num / 10; } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no = it will hold the integer value of number input.
- num = it will hold the integer value of number input.
Taking input number from the user.
Program logic.
Printing Output numbers.