
- 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
Write a C program to print numbers in words using elseif statements
Problem
Without using a switch case, how can you print a given number in words using the C programming language?
Solution
In this program, we are checking three conditions to print a two-digit number in words −
if(no<0 || no>99)
entered number is not a two digit
else if(no==0)
print first number as zero
else if(no>=10 && no<=19)
Print single digit number in words
else if(no>=20 && no<=90)
if(no%10 == 0)
Print two-digit number in words
Program
#include<stdio.h> #include<string.h> int main(){ int no; char *firstno[]={"zero","ten","eleven","twelve","thirteen", "fourteen","fifteen","sixteen","seventeen", "eighteen","nineteen"}; char *secondno[]={"twenty","thirty","forty","fifty","sixty", "seventy","eighty","ninty"}; char *thirdno[]={"one","two","three","four","five","six","seven","eight","nine"}; printf("enter a number:"); scanf("%d",&no); if(no<0 || no>99) printf("enter number is not a two digit number
"); else if(no==0) printf("the enter no is:%s
",firstno[no]); else if(no>=10 && no<=19) printf("the enter no is:%s
",firstno[no-10+1]); else if(no>=20 && no<=90) if(no%10 == 0) printf("the enter no is:%s
",secondno[no/10 - 2]); else printf("the enter no is:%s %s
",secondno[no/10-2],thirdno[no%10-1]); return 0; }
Output
enter a number:79 the enter no is: seventy nine enter a number:234 enter number is not a two digit number
- Related Articles
- Write a C program for time conversions using if and elseif statements
- C++ program to convert digits to words using conditional statements
- C++ program to print unique words in a file
- Write a C program to work on statements using functions and loops
- Write a program to print ‘Tutorials Point’ without using a semicolon in C
- Program to print prime numbers in a given range using C++ STL
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Python program to print Possible Words using given characters
- C program to write all digits into words using for loop
- Write a program to add two complex numbers using C
- How to print the numbers in different formats using C program?
- Program to print a pattern of numbers in C++
- Print numbers in sequence using thread synchronization in C Program.
- Program to print numbers columns wise in C
- C Program to print numbers from 1 to N without using semicolon

Advertisements