I need to write a program that prints the lowercase English word corresponding to the number (e.g., one for 1, two for 2, etc.). If n>9, print: Greater than 9.
#include <stdio.h>
#include <string.h>
int main()
{
int n;
scanf("%d", &n);
char keySet[9][5] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
if (n > 9)
{
printf("Greater than 9");
}
else
{
n -= 1;
puts(keySet[n]);
}
}
For a positive int n, do the following:
- If [1 ≤ n ≤ 9] print the lowercase English word corresponding to the number (e.g., one for 1, two for 2, etc.)
- If n>9, print Greater than 9
Behavior:
Input: 8
Output: eightnine
Desired behavior:
Input: 8
Output: eight
Basically, this is only happening with every string having 5 characters, to be exact.
Like "three" & "seven"
Behavior:
Input: 7
Output: seveneightnine
When variable char keySet is defined like char keySet[9][6] it works as expected...
Putting value more than 5 works but not 5 itself not clear about the issue