Home > Article > Backend Development > Write a C program to print numbers as words using elseif statement
How to print a given number in literal form using C programming language without using switch case?
In this program we check three conditions to print two digits in words-
if(no 99)
if(no99) p>
The number entered is not a two-digit number
else if( no==0)
Print the first number as zero
else if(no>=10 && no
Print single digits in text
else if(no>=20 && no
if(no == 0)
Print two digits with text
Live demonstration
#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</p><p>"); else if(no==0) printf("the enter no is:%s</p><p>",firstno[no]); else if(no>=10 && no<=19) printf("the enter no is:%s</p><p>",firstno[no-10+1]); else if(no>=20 && no<=90) if(no%10 == 0) printf("the enter no is:%s</p><p>",secondno[no/10 - 2]); else printf("the enter no is:%s %s</p><p>",secondno[no/10-2],thirdno[no%10-1]); return 0; }
enter a number:79 the enter no is: seventy nine enter a number:234 enter number is not a two digit number
The above is the detailed content of Write a C program to print numbers as words using elseif statement. For more information, please follow other related articles on the PHP Chinese website!