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

What are the salient features of c languages?

616


Explain zero based addressing.

595


please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1700


Can you please explain the difference between strcpy() and memcpy() function?

590


What does static variable mean in c?

641






What is character set?

675


Is c is a procedural language?

586


What are the different types of linkage exist in c?

603


What is c++ used for today?

649


What is a function simple definition?

604


In c language can we compile a program without main() function?

567


main use of recursive function a) processing speed high b) reduce program length/reduce repeated statements c) if you do not, use iterative methods like, for, while or do-while d) all the above

605


Can you please explain the difference between syntax vs logical error?

682


How can you restore a redirected standard stream?

597


what will be the output for the following main() { printf("hi" "hello"); }

9297