Friday, 21 December 2012

C Program to Display Number in Words OR Input a Number and Display it in Words

#include<stdio.h>
#include<conio.h>
void main()
{
   int num,a,x,y,z,w;
   clrscr();
   printf("Enter any Four Digit Number");
   scanf("%d",&num);
   a=num/1000;

    if (a == 1)
    {
        printf("One Thousand ");
    }
    else if (a == 2)
    {
        printf("Two Thousand ");
    }
    else if (a == 3)
    {
        printf("Three Thousand ");
    }
    else if (a == 4)
    {
        printf("Four Thousand ");
    }
    else if (a == 5)
    {
        printf("Five Thousand ");
    }
    else if (a == 6)
    {
        printf("Six thousand ");
    }
    else if (a == 7)
    {
        printf("Seven Thousand ");
    }
    else if (a == 8)
    {
        printf("Eight Thousand ");
    }
    else if (a == 9)
    {
        printf("Nine Thousand ");
    }

    y = num % 1000;
    if (y >= 100 && y < 200)
    {
        printf(" One Hundred ");
    }
    else if (y >= 200 && y < 300)
    {
        printf(" Two Hundred ");
    }
    else if (y >= 300 && y < 400)
    {
        printf(" Three Hundred ");
    }
    else if (y >= 400 && y < 500)
    {
        printf(" Four Hundred ");
    }
    else if (y >= 500 && y < 600)
    {
        printf(" Five Hundred ");
    }
    else if (y >= 600 && y < 700)
    {
        printf(" Six Hundred ");
    }
    else if (y >= 700 && y < 800)
    {
        printf(" Seven Hundred ");
    }
    else if (y >= 800 && y < 900)
    {
        printf(" Eight Hundred ");
    }
    else if (y >= 900 && y < 1000)
    {
       printf(" Nine Hundred ");
    }

    z = num % 100;
    w = z;
    if (z >= 20 && z < 30)
    {
        printf(" Twenty ");
    }
    else if (z >= 30 && z < 40)
    {
        printf(" Thirty ");
    }
    else if (z >= 40 && z < 50)
    {
        printf(" Forty ");
    }
    else if (z >= 50 && z < 60)
    {
        printf(" Fifty ");
    }
    else if (z >= 60 && z < 70)
    {
        printf(" Sixty ");
    }
    else if (z >= 70 && z < 80)
    {
        printf(" Seventy ");
    }
    else if (z >= 80 && z < 90)
    {
       printf(" Eighty ");
    }
    else if (z >= 90 && z < 100)
    {
        printf(" Ninety ");
    }
    else if (z >= 10 && z < 20)
    {
        w = z;
    }

    if (w == 10)
    {
        printf(" Ten ");
    }
    else if (w == 11)
    {
        printf(" Eleven ");
    }

    else if (w == 12)
    {
        printf(" Twelve ");
    }

    else if (w == 13)
    {
        printf(" Thirteen ");
    }
    else if (w == 14)
    {
        printf(" Forteen ");
    }
    else if (w == 15)
    {
       printf(" Fifteen ");
    }
    else if (w == 16)
    {
        printf(" Sixteen ");
    }
    else if (w == 17)
    {
        printf(" Seventeen ");
    }
    else if (w == 18)
    {
        printf(" Eighteen ");
    }
    else if (w == 19)
    {
        printf(" Nineteen ");
    }

    if (z < 10 || z >= 20)
    {
        x = z % 10;

        if (x == 1)
        {
        printf(" One ");
        }
        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 ");
        }
            else if(x== 0)
            {
               printf("Zero");
            }
    }
getch();

}


========OUTPUT===============
Like as:-----

1.


2.



3.




4.



5.

No comments:

Post a Comment