Computer Science, asked by skandalkar1508, 3 months ago

a flowchart of program to convert numbers into words in c language ​

Answers

Answered by officialakshay3105
0

Answer:

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

void main()

{

char num[3];

void convert_to_words(char*);

clrscr();

printf(“Enter any number between 1 to 299 : “);

scanf(“%s”,&num);

convert_to_words(num);

getch();

}

void convert_to_words(char *num)

{

char *single_digits[] = { “zero”, “one”, “two”, “three”, “four”,

“five”, “six”, “seven”, “eight”, “nine”};

char *two_digits[] = {“”, “ten”, “eleven”, “twelve”, “thirteen”, “fourteen”,

“fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”};

char *tens_multiple[] = {“”, “”, “twenty”, “thirty”, “forty”, “fifty”,

“sixty”, “seventy”, “eighty”, “ninety”};

int len = strlen(num);

printf(“\n%s: “, num);

if (len == 1)

{

printf(“%s\n”, single_digits[*num – ‘0’]);

return;

}

while (*num != ‘\0’)

{

if (len == 3)

{

if (*num -‘0’ != 0)

{

printf(“%s “, single_digits[*num – ‘0’]);

printf(“hundred “);

}

–len;

}

else

{

if (*num == ‘1’)

{

int sum = *num – ‘0’ + *(num + 1)- ‘0’;

printf(“%s\n”, two_digits[sum]);

return;

}

else if (*num == ‘2’ && *(num + 1) == ‘0’)

{

printf(“twenty\n”);

return;

}

else

{

int i = *num – ‘0’;

printf(“%s “, i? tens_multiple[i]: “”);

++num;

if (*num != ‘0’)

printf(“%s “, single_digits[*num – ‘0’]);

}

}

++num;

}

}

Explanation:

OUTPUT

ENTER ANY NUMBER BETWEEN (1-299) 5

FIVE

Similar questions