|
INTERVIEW QUESTIONS
C
STRINGS IN C
DETAILS
Question: Write to program to accept any number upto 7 digits and convert this number into words like this e.g. 25525 :- twenty five thousands five hundred twenty five.
Answer: #include<stdio.h>
void pw(long,char[]); char *one[]={" "," one"," two"," three"," four"," five"," six"," seven"," eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"}; char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty"," seventy"," eighty"," ninety"};
void main() { long n; clrscr(); printf(" Enter any 9 digit no: "); scanf("%9ld",&n); if(n<=0) printf("Enter numbers greater than 0"); else { pw((n/10000000),"crore"); pw(((n/100000)%100),"lakh"); pw(((n/1000)%100),"thousand"); pw(((n/100)%10),"hundred"); pw((n%100)," "); } getch(); }
void pw(long n,char ch[]) { (n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]); if(n)printf("%s ",ch); }
|
|
|
Category |
Strings in C Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9715 users |
Added on |
4/8/2015 |
Views |
67604 |
Rate it! |
|
|
Question:
Write to program to accept any number upto 7 digits and convert this number into words like this e.g. 25525 :- twenty five thousands five hundred twenty five.
Answer:
#include<stdio.h>
void pw(long,char[]); char *one[]={" "," one"," two"," three"," four"," five"," six"," seven"," eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen"," fifteen"," sixteen"," seventeen"," eighteen"," nineteen"}; char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty"," seventy"," eighty"," ninety"};
void main() { long n; clrscr(); printf(" Enter any 9 digit no: "); scanf("%9ld",&n); if(n<=0) printf("Enter numbers greater than 0"); else { pw((n/10000000),"crore"); pw(((n/100000)%100),"lakh"); pw(((n/1000)%100),"thousand"); pw(((n/100)%10),"hundred"); pw((n%100)," "); } getch(); }
void pw(long n,char ch[]) { (n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]); if(n)printf("%s ",ch); } Source: CoolInterview.com
Answered by: clara phillips | Date: 6/24/2010
| Contact clara phillips
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Explain one method to process an entire string as one unit?
|
View Answer
|
|
How would you implement a sbstr()function that extract a sub string from a givn string?
|
View Answer
|
|
How do you print a string on the pointer?
|
View Answer
|
|
Why doesn’t strcat (string, ‘!’); work ?
|
View Answer
|
|
How can i print a’%’ character in a print format string?
|
View Answer
|
|
Tell me the difference between strdup and strcpy?
|
View Answer
|
|
Write a C program that will convert Simple Sentence to Complex/Compound Sentence.
|
View Answer
|
|
If a string variable contain "i am a good boy" then how a c program will print "boy good a am i".?
|
View Answer
|
|
How do I use c-strings to write a c program that Removes multiple spaces between words in a paragraph?
|
View Answer
|
|
How to get string in files and print the string in the reverse order?
|
View Answer
|
|
How can I convert a number to a string?
|
View Answer
|
|
i need a code in c for strings and general, which are important and frequently asked in programming test especially for SUBEX.
|
View Answer
|
|
What is the difference between a string and an array?
|
View Answer
|
|
How can I convert a number to a string?
|
View Answer
|
|
Following declarations are different from one another const char *const s; char const *const s;
|
View Answer
|
|
Can we use string in switch statement?
|
View Answer
|
|
What is wrong with the following c program? char *s1 = "hello"; char *s2 = "world"; char *s3 = strcat(s1, s2);
Please provide me explanations??
|
char *s2 = "world"; char *s - Strings in C Interview Questions & Answers">
View Answer
|
|
Write a program which accepts a filename as a command line argument and coverts all characters in the file to uppercase.
|
View Answer
|
|
How to type a string without using printf function?
|
View Answer
|
|
What is the difference between System.String and System.StringBuilder classes?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Strings in C Interview Questions & Answers - Exam Mode /
Learning Mode
|