Mr. Uncle is very happy with the skills of PS & CP students. He would like you to solve a new problem that takes amount as integer num in input and output its value in words. You are required to generalize the solution for any amount. Write a C Program for solving this problem.
INPUT SIMPLE:
Sample Input
Sample Output
2000
Two Thousand Rupees
545
Five hundred and Forty Five Rupees
1300
Thirteen Hundred Rupees
100000
One Hundred Thousand Rupees 1000000000
One Billion Rupees
CODE:
#include<stdio.h>
main ()
{
int num=0;
int th=0,u=0;
int hn=0,tn=0,Thous=0,lac=0,millions=0,ten_millions=0,hundred_millions=0,billions=0;
printf("Enter value which you want convert to words:");
scanf("%d",&num);
{
printf("num=%d\n",num);
}
billions=num/1000000000;
if(billions==1)
{
printf("one ");
}
if(billions==2)
{
printf("Two ");
}
if(billions==3)
{
printf("Three");
}
if(billions==4)
{
printf("Four ");
}
if(billions==5)
{
printf("Fife ");
}
if(billions==6)
{
printf("Six ");
}
if(billions==7)
{
printf("Seven ");
}
if(billions==8)
{
printf("Eight ");
}
if(billions==9)
{
printf("Nine ");
}
if(billions>0)
{
printf("billions ");
}
num=num%1000000000;
hundred_millions=num/100000000 ;
if(hundred_millions==1)
{
printf("one ");
}
if(hundred_millions==2)
{
printf("Two ");
}
if(hundred_millions==3)
{
printf("Three");
}
if(hundred_millions==4)
{
printf("Four ");
}
if(hundred_millions==5)
{
printf("Fife ");
}
if(hundred_millions==6)
{
printf("Six ");
}
if(hundred_millions==7)
{
printf("Seven ");
}
if(hundred_millions==8)
{
printf("Eight ");
}
if(hundred_millions==9)
{
printf("Nine ");
}
if(hundred_millions>0)
{
printf("hundred millions ");
}
num=num%100000000 ;
ten_millions=num/10000000;
if(ten_millions==1)
{
printf("Ten ");
}
if(ten_millions==2)
{
printf("Twenty ");
}
if(ten_millions==3)
{
printf("Thirty ");
}
if(ten_millions==4)
{
printf("Fourty ");
}
if(ten_millions==5)
{
printf("Fifty ");
}
if(ten_millions==6)
{
printf("Sixty ");
}
if(ten_millions==7)
{
printf("Seventy ");
}
if(ten_millions==8)
{
printf("Eighty ");
}
if(ten_millions==9)
{
printf("Ninety ");
}
if(ten_millions>0)
{
printf("millions ");
}
num=num%10000000;
millions=num/1000000;
if(millions==1)
{
printf("one ");
}
if(millions==2)
{
printf("Two ");
}
if(millions==3)
{
printf("Three");
}
if(millions==4)
{
printf("Four ");
}
if(millions==5)
{
printf("Fife ");
}
if(millions==6)
{
printf("Six ");
}
if(millions==7)
{
printf("Seven ");
}
if(millions==8)
{
printf("Eight ");
}
if(millions==9)
{
printf("Nine ");
}
if(millions>0)
{
printf("millions ");
}
num=num%1000000;
lac=num/100000;
if(lac==1)
{
printf("one ");
}
if(lac==2)
{
printf("Two ");
}
if(lac==3)
{
printf("Three");
}
if(lac==4)
{
printf("Four ");
}
if(lac==5)
{
printf("Fife ");
}
if(lac==6)
{
printf("Six ");
}
if(lac==7)
{
printf("Seven ");
}
if(lac==8)
{
printf("Eight ");
}
if(lac==9)
{
printf("Nine ");
}
if(lac>0)
{
printf("Hundred Thousands");
}
num=num%100000;
Thous=num/10000;
if(Thous==1)
{
printf("Ten ");
}
if(Thous==2)
{
printf("Twenty ");
}
if(Thous==3)
{
printf("Thirty ");
}
if(Thous==4)
{
printf("Fourty ");
}
if(Thous==5)
{
printf("Fifty ");
}
if(Thous==6)
{
printf("Sixty ");
}
if(Thous==7)
{
printf("Seventy ");
}
if(Thous==8)
{
printf("Eighty ");
}
if(Thous==9)
{
printf("Ninety ");
}
if(Thous==12)
{
printf("tweleve");
}
if(Thous>0)
{
printf("thousand ");
}
num=num%10000;
th=num/1000;
if(th==1)
{
printf("One ");
}
if(th==2)
{
printf("two ");
}
if(th==3)
{
printf("Three ");
}
if(th==4)
{
printf("Four ");
}
if(th==5)
{
printf("Five ");
}
if(th==6)
{
printf("Six ");
}
if(th==7)
{
printf("Seven ");
}
if(th==8)
{
printf("Eight ");
}
if(th==9)
{
printf("Nine ");
}
if(th>0)
{
printf("Thousand ");
}
num=num%1000;
hn=num/100;
if(hn==1)
{
printf("One ");
}
if(hn==2)
{
printf("two ");
}
if(hn==3)
{
printf("Three ");
}
if(hn==4)
{
printf("Four ");
}
if(hn==5)
{
printf("Five ");
}
if(hn==6)
{
printf("Six ");
}
if(hn==7)
{
printf("Seven ");
}
if(hn==8)
{
printf("Eight ");
}
if(hn==9)
{
printf("Nine ");
}
if(hn>0)
{
printf("Hundred ");
}
num=num%100;
tn=num/10;
if(tn==2)
{
printf("twenty ");
}
if(tn==3)
{
printf("Thirty ");
}
if(tn==4)
{
printf("Fourty ");
}
if(tn==5)
{
printf("Fifty ");
}
if(tn==6)
{
printf("Sixty ");
}
if(tn==7)
{
printf("Seventy ");
}
if(tn==8)
{
printf("Eighty ");
}
if(tn==9)
{
printf("Ninety ");
}
if(tn==1)
{
num=num%10;
u=num;
if(u==1)
{
printf("Eleven ");
}
if(u==2)
{
printf("tweleve ");
}
if(u==3)
{
printf("Thirteen ");
}
if(u==4)
{
printf("Fourteen ");
}
if(u==5)
{
printf("Fifteen ");
}
if(u==6)
{
printf("Sixteen ");
}
if(u==7)
{
printf("Seventeen ");
}
if(u==8)
{
printf("Eighteen ");
}
if(u==9)
{
printf("Nineteen");
}
}
else{
num=num%10;
u=num;
if(u==1)
{
printf("One ");
}
if(u==2)
{
printf("two ");
}
if(u==3)
{
printf("Three ");
}
if(u==4)
{
printf("Four ");
}
if(u==5)
{
printf("Five ");
}
if(u==6)
{
printf("Six ");
}
if(u==7)
{
printf("Seven ");
}
if(u==8)
{
printf("Eight ");
}
if(u==9)
{
printf("Nine ");
}
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment