Algorithm
1. It is taking input from keyboard .
2. According to size of number , passing to function
3. From their , it is calling recursive to other functions
#include<stdio.h>
void onedigit(int num);
void twodigit(int num);
void threedigit(int num);
void fourdigit(int num);
void fivedigit(int num);
int main()
{
int number;
int copy;
int increment=0;
printf("Enter a number \n");
scanf("%d",&number);
copy=number;
while(copy!=0)
{
increment++;
copy/=10;
}
if(increment<0||increment>999999)
{
printf("Please enter positive or less than six digit number");
}
else
{
if(increment==0)
printf("zero enter");
else if(increment==1)
onedigit(number);
else if(increment==2)
twodigit(number);
else if(increment==3)
threedigit(number);
else if(increment==4)
fourdigit(number);
else if(increment==5)
fivedigit(number);
}
}
void onedigit(int number)
{
switch(number)
{
case 1:
printf("One");break;
case 2:
printf("Two");break;
case 3:
printf("Three");break;
case 4:
printf("Four");break;
case 5:
printf("Five");break;
case 6:
printf("Six");break;
case 7:
printf("Seven");break;
case 8:
printf("Eight");break;
case 9:
printf("Nine");break;
}
}
void twodigit(int num)
{
if(num>10 && num<20)
{
switch (num)
{
case 11:
printf("Eleven");break;
case 12:
printf("Twelve");break;
case 13:
printf("Thirteen");break;
case 14:
printf("Fourteen");break;
case 15:
printf("Fifteen");break;
case 16:
printf("Sixteen");break;
case 17:
printf("Seventeen");break;
case 18:
printf("Eighteen");break;
case 19:
printf("Ninteen");break;
}
}
else
{
if(num>=90)
{
printf("Ninty ");
}
else if(num>=80)
{
printf("Eighty ");
}
else if(num>=70)
{
printf("Seventy ");
}
else if(num>=60)
{
printf("Sixty ");
}
else if(num>=50)
{
printf("Fifty ");
}
else if(num>=40)
{
printf("Fourty ");
}
else if(num>=30)
{
printf("Thirty ");
}
else if(num>=20)
{
printf("Twenty ");
}
else if (num>=10)
{
printf("Ten ");
}
onedigit(num%10);
}
}
void threedigit(int num)
{
if(num>=900)
{
printf("Nine Hundred ");
}
else if(num>=800)
{
printf("Eight Hundred ");
}
else if(num>=700)
{
printf("Seven Hundred ");
}
else if(num>=600)
{
printf("Six Hundred ");
}
else if(num>=500)
{
printf("Five Hundred ");
}
else if(num>=400)
{
printf("Four Hundred ");
}
else if(num>=300)
{
printf("Three Hundred ");
}
else if(num>=200)
{
printf("Two Hundred ");
}
else if (num>=100)
{
printf("One Hundred ");
}
twodigit(num%100);
}
void fourdigit(int num)
{
if(num>=9000)
{
printf("Nine Thousand ");
}
else if(num>=8000)
{
printf("Eight Thousand ");
}
else if(num>=7000)
{
printf("Seven Thousand ");
}
else if(num>=6000)
{
printf("Six Thousand ");
}
else if(num>=5000)
{
printf("Five Thousand ");
}
else if(num>=4000)
{
printf("Four Thousand ");
}
else if(num>=3000)
{
printf("Three Thousand ");
}
else if(num>=2000)
{
printf("Two Thousand ");
}
else if (num>=1000)
{
printf("One Thousand ");
}
threedigit(num%1000);
}
void fivedigit(int num)
{
int flag=0;
int copy;
copy=num;
if(num>=90000)
{
if(num==90000)
printf("Ninty Thousand ");
else
printf("Ninty ");
}
else if(num>=80000)
{
if(num==80000)
printf("Eighty Thousand ");
else
printf("Eighty ");
}
else if(num>=70000)
{
if(num==70000)
printf("Seventy Thousand");
else
printf("Seventy ");
}
else if(num>=60000)
{
if(num==60000)
printf(" Sixty Thousand");
else
printf("Sixty ");
}
else if(num>=50000)
{
if(num==50000)
printf(" Fifty Thousand");
else
printf("Fifty ");
}
else if(num>=40000)
{
if(num==40000)
printf(" Fourty Thousand ");
else
printf("Fourty ");
}
else if(num>=30000)
{
if(num==30000)
printf("Thirty Thousand");
else
printf("Thirty ");
}
else if(num>=20000)
{
if(num==20000)
printf(" Twenty Thousand");
else
printf("Twenty ");
}
else if (num>=10000)
{
if(num==10000)
printf(" Ten Thousand");
else
{
copy=num/1000;
twodigit(copy);
printf(" Thousand ");
flag=1;
threedigit(num%1000);
}
}
if(flag==0)
fourdigit(num%10000);
}
No comments:
Post a Comment