/* This program takes an integer and READS it in ENGLSIH
I am just a beginner programmer. So there may be some mistakes.
Do Let me Know about them..
comments and Suggestions Are welcomed
My email is bforbilal@hotmail.com */
#include <stdio.h>
void main (void)
{
void read(void); // Function Prototype
read(); // read() function will be invoked
}
void read()
{
void onetoten(int); //Function prototype
void elevenTO19(int); //Function Prototype
int n,s,q; //variable declaration
printf("\nEnter INTEGER Between 0 to 9999\n" );
scanf("%d",&n); //Number is stored in n
if (n==0)
printf("Zero");
q=n/1000;
switch (q)
{
case 1:
printf("One Thousand ");
n=n-1000; // Subtracting to eleminate thousand digit from number
break;
case 2:
printf("Two Thousand ");
n=n-2000; // Subtracting to eleminate thousand digit from number
break;
case 3:
printf("Three Thousand ");
n=n-3000; // Subtracting to eleminate thousand digit from number
break;
case 4:
printf("Four Thousand ");
n=n-4000; // Subtracting to eleminate thousand digit from number
break;
case 5:
printf("Five Thousand ");
n=n-5000; // Subtracting to eleminate thousand digit from number
break;
case 6:
printf("Six Thousand ");
n=n-6000; // Subtracting to eleminate thousand digit from number
break;
case 7:
printf("Seven Thousand ");
n=n-7000; // Subtracting to eleminate thousand digit from number
break;
case 8:
printf("Eight Thousand ");
n=n-8000; // Subtracting to eleminate thousand digit from number
break;
case 9:
printf("Nine Thousand ");
n=n-9000; // Subtracting to eleminate thousand digit from number
break;
}// End switch
q=n/100; // Dividing by 100 to get the Hundreth Digit of number
s=q*100 ; // Multiplying the hundreth number by 100 to make my life easy
switch (s) //switching w.r.t the hundreth digit and printing accordingly
{
case 100:
printf("One Hundred and ");
n=n-100; // Subtracting to eleminate hundreth digit from number
break;
case 200:
printf("Two Hundred and ");
n=n-200; // Subtracting to eleminate hundreth digit from number
break;
case 300:
printf("Three Hundred and ");
n=n-300; // Subtracting to eleminate hundreth digit from number
break;
case 400:
printf("Four Hundred and ");
n=n-400; // Subtracting to eleminate hundreth digit from number
break;
case 500:
printf("Five Hundred and ");
n=n-500; // Subtracting to eleminate hundreth digit from number
break;
case 600:
printf("Six Hundred and ");
n=n-600; // Subtracting to eleminate hundreth digit from number
break;
case 700:
printf("Seven Hundred and ");
n=n-700; // Subtracting to eleminate hundreth digit from number
break;
case 800:
printf("Eight Hundred and ");
n=n-800; // Subtracting to eleminate hundreth digit from number
break;
case 900:
printf("Nine Hundred and ");
n=n-900; // Subtracting to eleminate hundreth digit from number
break;
}// End switch
if (n>=1)
{
if (n<=10)
{
onetoten(n); // Function To print one to ten will be invoked
// if number after subtraction is greater than 0
//and less than 11
}
}
if (n>=11)
{
if (n<=19)
{
elevenTO19(n);// Function To print Eleven to NINETEEN will be invoked
// if number after subtraction is greater than 10
//and less than 20
}
else
{
q=n/10; // Dividing by 10 to get TENTH digit of number
s=q*10; // Multiplying by 10 to make understanding easy
switch (s)
{
case 20:
printf("Twenty ");
n=n-20; // Subtracting to Eleminate the TENTH digit from number
break;
case 30:
printf("Thirty ");
n=n-30; // Subtracting to Eleminate the TENTH digit from number
break;
case 40:
printf("Forty ");
n=n-40; // Subtracting to Eleminate the TENTH digit from number
break;
case 50:
printf("Fifty ");
n=n-50; // Subtracting to Eleminate the TENTH digit from number
break;
case 60:
printf("Sixty ");
n=n-60; // Subtracting to Eleminate the TENTH digit from number
break;
case 70:
printf("Seventy ");
n=n-70; // Subtracting to Eleminate the TENTH digit from number
break;
case 80:
printf("Eighty ");
n=n-80; // Subtracting to Eleminate the TENTH digit from number
break;
case 90:
printf("Ninety ");
n=n-90; // Subtracting to Eleminate the TENTH digit from number
}// End switch
if (n==0) // If number has become 0 after the above Subtraction
// Then do nothing other wise Print accordingly
{
;
}
else
onetoten(n); //Function of printing one to ten will be invoked
}
}
}
// Function to print one to Ten
void onetoten (int s)
{
switch (s)
{
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;
case 10:
printf("Ten");
}// End switch
}
// Function to print eleven to Nineteen
void elevenTO19(int n)
{
switch (n)
{
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("Nineteen");
break;
}
}