Add to Favorites    Make Home Page 4107 Online  
 Language Categories  
 Our Services  

Home » C Home » Data Structures Home » Conversion of numbers to English words(Using Stack)

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Conversion of numbers to English words(Using Stack)
Author Himanshu Sardana
Author Email sardana_himanshu [at] rediffmail.com
Description This program converts any given number upto 999999999 into
english and reports it to the user.
for eg - 01024 is reported as One Thousand AND Twenty four.This program
internally makes use of stack but user of program is unaware of this.

Category C » Data Structures
Hits 379614
Code Select and Copy the Code
/* Program to take an input in form of number and display it in words. The number ranges from 0 to 999999999 */ #include<stdio.h> #include<conio.h> #define SIZE 9 int top = -1; int stack[SIZE]; int nested_flag = 1; void push(int item) { if(top==SIZE-1) { printf(" Number too big.Stack overflow. "); printf("Press any key to exit......"); getch(); exit(0); } else stack[++top] = item; } void print(int num) { switch(num) { 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 print_pair(int num) { switch(num) { case 1: switch(stack[top]) { case 1: printf("Eleven "); break; case 2: printf("Twelve "); break; case 3: printf("Thirteen "); break; case 4: printf("Fourteen "); break; case 5: printf("Fifteen "); break; case 6: printf("Sixteen "); break; case 7: printf("Seventeen "); break; case 8: printf("Eighteen "); break; case 9: printf("Nineteen "); break; case 0: printf("Ten "); nested_flag = 0; } break; case 2: printf("Twenty "); break; case 3: printf("Thirty "); break; case 4: printf("Forty "); break; case 5: printf("Fifty "); break; case 6: printf("Sixty "); break; case 7: printf("Seventy "); break; case 8: printf("Eighty "); break; case 9: printf("Ninety "); break; } } void translate(int length) { if(length==9) { print_pair(stack[top--]); if(stack[top+1]!=1 && nested_flag) print(stack[top--]); else top--; printf("Crores "); } if(length>=7) { if(length==8) { print(stack[top--]); printf("Crores "); } print_pair(stack[top--]); if(stack[top+1]!=1 && nested_flag) print(stack[top--]); else top--; if(stack[6]!=0||stack[5]!=0) printf("Lakhs "); if(nested_flag==0) nested_flag = 1; } if(length>=5) { if(length==6) { print(stack[top--]); printf("Lakhs "); } print_pair(stack[top--]); if(stack[top+1]!=1 && nested_flag) print(stack[top--]); else top--; if(stack[4]!=0||stack[3]!=0) printf("Thousand "); if(nested_flag==0) nested_flag = 1; } if(length>=3) { if(length==4) { print(stack[top--]); printf("Thousand "); } print(stack[top--]); if(stack[2]!=0) printf("Hundered "); if(stack[1]==0&&stack[0]!=0) { printf("AND "); print(stack[0]); } else if(stack[1]!=0) { printf("AND "); print_pair(stack[top--]); if(stack[top+1]!=1 && nested_flag) print(stack[top--]); } } if(length==2) { print_pair(stack[top--]); if(stack[top+1]!=1 && nested_flag) print(stack[top--]); if(nested_flag==0) nested_flag = 1; } if(length==1) print(stack[top--]); } void main() { long number; clrscr(); printf("Enter the number to be translated: "); scanf("%ld",&number); while(number>0) { push(number%10); number = number/10; } translate(top+1); getch(); }t

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi դ ? ??
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=1093


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review