
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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\n"); else if(no==0) printf("the enter no is:%s\n",firstno[no]); else if(no>=10 && no<=19) printf("the enter no is:%s\n",firstno[no-10+1]); else if(no>=20 && no<=90) if(no%10 == 0) printf("the enter no is:%s\n",secondno[no/10 - 2]); else printf("the enter no is:%s %s\n",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 Questions & Answers
- Write a C program for time conversions using if and elseif statements
- C++ program to convert digits to words using conditional statements
- Write a C program to work on statements using functions and loops
- C++ program to print unique words in a file
- Write a program to add two complex numbers using C
- C program to write all digits into words using for loop
- Python program to print Possible Words using given characters
- Program to print prime numbers in a given range using C++ STL
- Program to print a pattern of numbers in C++
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Write a program to print ‘Tutorials Point’ without using a semicolon in C
- How to print the numbers in different formats using C program?
- Write a C program to print all files and folders.
- Print numbers in sequence using thread synchronization in C Program.
- Write a program to print message without using println() method in java?
Advertisements