Write a c program to read a positive number and display it
in words.?
ex: 123=one two three


help me....

Answer Posted / sanjay

Hi this is the complete solution for your answer..

#include <stdio.h>
#include <conio.h>
#include <string.h>

char* displaynum( int);

main(){
char str[10], str1[10];
char *p1;
unsigned int num, n_num;

printf("Enter the number to print : ");
scanf("%d", &num);

itoa (num , str, 10);
p1=strrev(str);
n_num=atoi(p1);

printf("Number %d in words is > ", n_num);
while(n_num){
p1=displaynum(n_num%10);
n_num=n_num/10;
}
printf("<\n");
getch();
}
char* strrev(char *s)
{
int i, j;
char t[10];
strcpy(t,s);
for(i = 0 , j = strlen(s) - 1 ; j >= 0 ; i++, j--)
*(s + i) = *(t + j);
return s;
}
char* displaynum( int disp){
char *s;
switch(disp){
case 0:
printf("Zero ");
break;
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;
default:
printf("Not a integer value");
}
}

Is This Answer Correct ?    4 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain how can I convert a string to a number?

643


What is the stack in c?

720


How do I create a directory? How do I remove a directory (and its contents)?

606


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

809


What is clrscr in c?

677






What is build process in c?

645


#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }

717


What is scope rule in c?

605


The file stdio.h, what does it contain?

667


Is main is user defined function?

597


a value that does not change during program execution a) variabe b) argument c) parameter d) none

696


What are the c keywords?

750


How many header files are in c?

551


Why is c called a mid-level programming language?

728


Tell me what are bitwise shift operators?

658