Amount in to text conversion program in C

#include<stdio.h>
#include<conio.h>
void dig1(long int x);
void dig2(long int x);
void dig3(long int x);
void dig4(long int x);
void main()
{
long int x,tx;
int cd=0;
clrscr();
printf("Enter a number\n");
scanf("%ld",&x);
printf("\n Given amount=%ld",x);
printf("\nAmount in literal:\n");
tx=x;
top:
cd++;
x=x/10;
if(x>0)
{
      //cd++;
goto top;
}
//printf("\nTotal Digit: %d\n",cd);
switch(cd)
{
case 1:
dig1(tx);
break;
case 2:
dig2(tx);
break;
case 3:
dig3(tx);
break;
case 4:
dig4(tx);
break;
default:
printf("Not more then %d digit evoluated",cd-1);
}
getch();

}
void dig1(long int x)
{
if(x==1)
{
printf("one");
}
else if(x==0)
{
printf("zero");
}
else if(x==2)
printf("two");
else if(x==3)
printf("three");
else if(x==4)
printf("four");
else if(x==5)
printf("five");
else if(x==6)
printf("six");
else if(x==7)
printf("seven");
else if(x==8)
printf("eight");
else if(x==9)
printf("nine");
}
void dig2(long int x)
{
long int tx=x;

x=(tx/10)*10;

if(x==10)
printf("ten ");
if(x==20)
printf("twenty ");
if(x==30)
printf("thirty ");
if(x==40)
printf("forty ");
if(x==50)
printf("fifty ");
if(x==60)
printf("sixty ");
if(x==70)
printf("seventy ");
if(x==80)
printf("eighty ");
if(x==90)
printf("ninenty ");

x=tx%10;
dig1(x);
}
void dig3(long int x)
{
long int tx;
tx=x;
x=(tx/100)*100;
if(x==100)
printf("hundred and ");
if(x==200)
printf("two hundred and ");
if(x==300)
printf("three hundred and ");
if(x==400)
       printf("four hundred and ");
if(x==500)
printf("five hundred and ");
if(x==600)
printf("six hundred and ");
if(x==700)
printf("seven hundred and ");
if(x==800)
printf("eight hundred and ");
if(x==900)
printf("nine hundred and ");

x=tx%100;
dig2(x);
}
void dig4(long int x)
{
long int tx=x;
x=(x/1000)*1000;
if(x==1000)
printf("one thousand ");
if(x==2000)
printf("two thousand ");
if(x==3000)
printf("three thousand ");
if(x==4000)
printf("four thousand ");
if(x==5000)
printf("five thousand ");
if(x==6000)
printf("six thousand ");
if(x==7000)
printf("seven thousand ");
if(x==8000)
printf("eight thousand ");
if(x==9000)
printf("nine thousand ");
x=tx%1000;
dig3(x);
}

Comments

Popular posts from this blog

Interface with extends

Abstract and Final Class sample