Integer Into Words

Discussion in 'C' started by bharathidhas, Jan 21, 2007.

  1. bharathidhas

    bharathidhas New Member

    Joined:
    Jan 21, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Coimbatore
    Code for Integer Into Words
    Code:
    #include<stdio.h>
    void main()
    {
    	long int n,t;
    	char a[][10]={" ","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
    	char b[][10]={" "," ","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
    	char c[][10]={" ","Leven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
    	clrscr();
    	printf("Enter a number\n");
    	scanf("%ld",&n);
    	if(n>1000&&n<10000)
    	{
    		t=n/1000;
    		printf("%s thousand ",a[t]);
    		n=n-(t*1000);
    	}
    	if(n>=100&&n<1000)
    	{
    		t=n/100;
    		if((t*100)==n)
    			printf("%s hundred",a[t]);
    		else
    			printf("%s hundred and ",a[t]);
    		n=n-(t*100);
    	}
    	if(n>10&&n<100)
    	{
    		if(n>10&&n<20)
    		{
    			t=n-10;
    			printf("%s ",c[t]);
    			n=100000;
    		}
    		else
    		{	t=n/10;
    		if((t*10)==n)
    			printf("%s ",b[t]);
    		else
    			printf("%s ",b[t]);
    		}	n=n-(t*10);
    	}
    	if(n>0&&n<=10)
    		printf("%s",a[n]);
    	getch();
    }
     
  2. rahul.mca2001

    rahul.mca2001 New Member

    Joined:
    Feb 13, 2008
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    0
    some problem is there
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice