Logical Analysis and Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Print number in words

2 posters

Go down

Print number in words Empty Print number in words

Post by Admin Wed Jun 24, 2015 10:52 pm

Write a program to print multi digit number in words.
Ex. I/P: 1583
O/P: one thousand five hundred eight tens three

    I/P: 1043
O/P: one thousand four tens three

Admin
Admin

Posts : 22
Points : 22749
Join date : 2015-06-24
Age : 29

https://csenpsb.board-directory.net

Back to top Go down

Print number in words Empty Re: Print number in words

Post by vinoveera Sat Jun 27, 2015 1:32 am

#include<stdio.h>
void main()
{
char a[10][10]={"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
char b[10][10]={"ELEVEN","TWELVE","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN",
"SEVENTEEN","EIGHTEEN","NINTEEN"};
char c[10][10]={"TEN","TWENTY","THIRTY","FOURTY","FIFTY","SIXTY","SEVENTY",
"EIGHTY","NINTY"};
int no,t;
printf("ttEnter the number");
scanf("%d",&no);
printf("tt");
if(no<9999)
{
if(no>1000)
{
 t=no/1000;
 no=no%1000;
 printf("%s THOUSAND",a[t-1]);
}
if(no>100)
{
 t=no/100;
 no=no%100;
 printf(" %s HUNDRED AND ",a[t-1]);
}
if(no>=10 && no<20)
{
 t=no/10;
 printf(" %s",b[t-1]);
}
if(no>19 && no<=100)
{
 t=no/10;
 no=no%10;
 printf("%s",c[t-1]);
}
if(no<10)
{
 printf(" %s",a[no-1]);
}
}
else
printf("ttEnter the small number");
return (0);
}

vinoveera

Posts : 7
Points : 22699
Join date : 2015-06-27

Back to top Go down

Print number in words Empty The answer to the program

Post by Admin Sat Jun 27, 2015 12:12 pm

#include<iostream.h>
void main()
{
int num,count=0,rem,tot=0;
cout<<"Enter the number to print in words: ";
cin>>num;
while(num>0)
{
rem=num%10;
tot=tot*10+rem;
num=num/10;
count++;
}
while(count>0)
{
rem=tot/10;
switch(rem)
{
case 1:cout<<"One ";
break;
case 2:cout<<"Two ";
break;
case 3:cout<<"Three ";
break;
case 4:cout<<"Four ";
break;
case 5:cout<<"Five ";
break;
case 6:cout<<"Six ";
break;
case 7:cout<<"Seven ";
break;
case 8:cout<<"Eight ";
break;
case 9:cout<<"Nine ";
}
if(count==4&&rem!=0)
{
cout<<"Thousand ";
count--;
}
else if(count==3&&rem!=0)
{
cout<<"Hundred ";
count--;
}
else if(count==2&&rem!=0)
{
cout<<"Ten(s) ";
count--;
}
else if(count==1&&rem!=0)
{
cout<<"One(s) ";
count--;
}
tot=tot/10;
}
}

Admin
Admin

Posts : 22
Points : 22749
Join date : 2015-06-24
Age : 29

https://csenpsb.board-directory.net

Back to top Go down

Print number in words Empty Re: Print number in words

Post by vinoveera Sun Jun 28, 2015 12:22 am

Hey My pgm also right la @admin

vinoveera

Posts : 7
Points : 22699
Join date : 2015-06-27

Back to top Go down

Print number in words Empty Re: Print number in words

Post by Admin Mon Jun 29, 2015 5:56 pm

vinoveera wrote:Hey My pgm also right la @admin

your program is absolutely perfect except only one error, you cannot return any value if its void. keep it up.. KUDOS!!!!

Admin
Admin

Posts : 22
Points : 22749
Join date : 2015-06-24
Age : 29

https://csenpsb.board-directory.net

Back to top Go down

Print number in words Empty Re: Print number in words

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum