pls anyone can help me to write a code to print the values
in words for any value.Example:1034 to print as "one
thousand and thirty four only"
Answers were Sorted based on User's Feedback
Answer / pavan_mustyala
Hi, This code works for 4 digit numbers(may be with some
minor exceptions). But i am trying a generic approach and
shall update very soon with more nicer solution.
/*************/
#include
char *arr1[10] =
{"One","Two","Three","Four","Five","Six","Seven","Eight","Ni
ne", "Ten"};
char *arr2[10] =
{"Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen"
,"Seventeen","Eighteen","Nineteen"};
char *arr3[10] =
{"Ten","Twenty","Thirty","Fourty","Fifty","sixty","Seventy",
"Eighty","Ninety","Hundred"};
char *arr4[10] = {"Hundred","Thousand"};
int CountGlobal;
int func(int);
void printWord(int, int);
int main(int argc, char* argv[])
{
int num = 2022;
int temp = num;
int count = 0;
// First count the number of digits in the given
number
while(temp)
{
temp /= 10;
count++;
}
CountGlobal = count;
while(count && num)
{
num = func(num);
count--;
}
return 0;
}
// Functions to print digits in words
int func(int num)
{
int temp = num;
int count = 0;
while(temp > 9)
{
temp /= 10;
count++;
}
printWord(temp,count+1);
while(count)
{
temp *= 10;
count--;
}
return(num - temp);
}
void printWord(int num, int count)
{
switch(count)
{
case 0:
//printf("%s", arr[num-1]);
break;
case 1:
printf("%s", arr1[num-1]);
break;
case 2:
printf("%s ", arr3[num-1]);
//printf("%s ", arr3[1]);
break;
case 3:
printf("%s ", arr1[num-1]);
printf("%s ", arr4[0]);
break;
case 4:
printf("%s ", arr1[num-1]);
printf("%s ", arr4[1]);
break;
case 5:
//printf("%s", arr[num-1]);
break;
default:
break;
}
}
/**********/
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / vin
not sure wether this is the best in performance.
need to use switch case.
string = "";
for lengh of the number
{
switch(char)
{
case 1:
string = string + one;
case 2:
string = string + two;
case 3:
string = string + three;
}
{
but that gives only letters into numbers.
for ex 1043 will be onezerothreefour
this does not end here, please modify or add.
as this has to be transformed into numebrsystem
| Is This Answer Correct ? | 0 Yes | 6 No |
#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above
int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too
In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }
#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,
abcdedcba abc cba ab ba a a
#include<stdio.h> int main() { int a=3,post,pre; post= a++ * a++ * a++; a=3; pre= ++a * ++a * ++a; printf("post=%d pre=%d",post,pre); return 0; }
There are 21 people in a room. They have to form groups of 3 people each. How many combinations are possible? Write a C program to print the same.
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped