Created
July 22, 2022 14:10
-
-
Save outlinepix/dcadbcfec712a428cd57ae08410d35bb to your computer and use it in GitHub Desktop.
Numbers to Indian currency text conversion in C Language Under 30 Lines(Noobish)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*/ Usage : <a.uot> <Number> "> | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
int main(int argc, char **argv){ | |
int num = atoi(argv[1]); | |
printf("%d : ", num); | |
char * oneToText[] = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen","Nineteen" }; | |
char * tenToText[] = {"", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}; | |
char * moreThenHundredToText[] = {"", "Hundred", "Thousand", "Lakhs", "Crore"}; | |
if (num >=10000000) printf("%s %s ", oneToText[num/10000000], moreThenHundredToText[4]); num = num % 10000000; | |
if (num >=100000) printf("%s %s ", oneToText[num/100000], moreThenHundredToText[3]); num = num % 100000; | |
if(num >=1000) printf("%s %s ", oneToText[num/1000], moreThenHundredToText[2]); num = num % 1000; | |
if(num >=100) printf("%s %s ", oneToText[num/100], moreThenHundredToText[1]); | |
if (num % 100 != 0) printf("and "); num = num%100; | |
if(num >=20) printf("%s ", tenToText[num/10]); num = num%10; | |
if ((int)num < 20){ | |
if(num%10 != 0) printf("and "); | |
printf("%s.", oneToText[num]); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment