Print integer in words again!

#include<stdio.h>
#include<stdlib.h>

void power(long,char[]);
char *ones[]={" "," One"," Two"," Three"," Four"," Five"," Six"," Seven","Eight"," Nine"," Ten"," Eleven"," Twelve"," Thirteen"," Fourteen","Fifteen"," Sixteen"," Seventeen"," Eighteen"," Nineteen"};
char *tens[]={" "," "," Twenty"," Thirty"," Forty"," Fifty"," Sixty","Seventy"," Eighty"," Ninety"};


int main()
{
    long long num;
    scanf("%lld",&num);
    if(num<=0)
        printf("Minus ");
    num=abs(num);
    power((num/100000000),"hundred");    
    power(((num/1000000)%100),"million");
    power(((num/100000)%100),"lakh");    
    power(((num/1000)%100),"thousand");
    power(((num/100)%10),"hundred and ");
    power((num%100)," ");
    return 0;
}

void power(long num,char ch[])
{
    (num>19)?printf("%s %s ",tens[num/10],ones[num%10]):printf("%s ",ones[num]);
    if(num)printf("%s ",ch);
}

Comments

Popular Posts