Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save outlinepix/ede330d7c761553119d88d2828ce68f8 to your computer and use it in GitHub Desktop.
Save outlinepix/ede330d7c761553119d88d2828ce68f8 to your computer and use it in GitHub Desktop.
Numbers to Indian currency text conversion in C Language detailed
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char **argv)
{
int num = atoi(argv[1]);
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");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment