
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
C Program for Print individual digits as words without using if or switch.
Print the given numeric value as words. It’s easy to do with switch using cases from 0-9 but challenge is without using them.
Input − N=900
Output − NINE ZERO ZERO
It is possible by creating array of pointers that contains 0-9 in words.
Algorithm
START Step 1 -> declare int variables num, i and array of pointer char *alpha with values {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"} Step 2 -> declare char array str[20] Step 3 -> call function itoa with parameters num,str,10 Step 4 -> Loop For i=0 and str[i]!=’\o’ and i++ Print alpha[str[i] - '0'] Step 5 -> End Loop STOP
Example
#include<stdio.h> #include<stdlib.h> int main() { int num, i; num=900; //lets take numeric value char *alpha[11] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"}; char str[20]; itoa(num, str, 10); //this function will convert integer to alphabet for(i=0; str[i] != '\0'; i++) printf("%s ", alpha[str[i] - '0']); return 0; }
Output
If we run above program then it will generate following output
Enter an integer 900 NINE ZERO ZERO
- Related Articles
- C program to write all digits into words using for loop
- C++ Program to Print “Even” or “Odd” without using conditional statement
- C Program to print “Even” or “Odd” without using Conditional statement
- Print all possible words from phone digits in C++
- C++ program to convert digits to words using conditional statements
- C program to print characters without using format specifiers
- Python Program for Print Number series without using any loop
- C# Program to convert Digits to Words
- C Program to print “Hello World!” without using a semicolon
- C program to print number series without using any loop
- Program to print root to leaf paths without using recursion using C++
- Write a C program to print numbers in words using elseif statements
- Python program to print Possible Words using given characters
- Print a character n times without using loop, recursion or goto in C++
- C Program to print numbers from 1 to N without using semicolon

Advertisements