Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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


help me....

Answers were Sorted based on User's Feedback



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

Answer / melwin

The input which is in integer form separate each number by / and % operator store it in array a[i],then using switch case function assign each case from 0 to 1 assigning each case with string, for eg case 1 shld have String "ONE" like wise till case 9, copy that function and store it an a variable using string copy function.then print the string,increment the value of array from i to i+1 and again repeat the switch case.and print the consecutive values.

Is This Answer Correct ?    5 Yes 1 No

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

Answer / 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

More C Interview Questions

How reliable are floating-point comparisons?

0 Answers  


What is external variable in c?

0 Answers  


how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--);

19 Answers   RMSI,


What is console in c language?

0 Answers  


How many types of functions are there in c?

0 Answers  






can please someone teach me how to create this program using while statement.. this is the output should look like 0 2 4 6 8 10 -thanks.. :) need it asap...

7 Answers  


cavium networks written test pattern ..

0 Answers   Cavium Networks,


write a program to delete an item from a particular location of an linear array?

1 Answers  


Describe for loop and write a c program to sum the series X + x2/2! + x3 /3! + …….. up to fifteen terms.

2 Answers  


write a c program to find the probability of random numbers between 1-1000

0 Answers   ADS,


What is the difference between realloc() and free()

1 Answers  


Hierarchy decides which operator a) is most important b) is used first c) is fastest d) operates on largest numbers

1 Answers  






Categories