The trouble here is I'd like the code to say the number correctly (1st, 2nd, 3rd, 21st, 22nd, 23rd etc), leave alone the problem with 11,12,13 (it can be easily fixed), but why does this simple modulo [ (i+1 % 10) ==1/2/3 ] does work only with 1, 2, and 3, and never after, so it produces "th" from else{} ? It should be straight forward, but if you take any number, for instance location 22 of the array (22+1 % 10) is clearly 3! so it should meet the condition (please note the +1 is due to 0 indexing)
for (int i = 0; i < arrLenght; i++)
{
if (array[i] == key)
{
if ((i+1 % 10) == 1)
{
printf("bravo! %i is the %ist number of the array! it's address is %p\n", key, i+1, &array[i]);
}
else if ((i+1 % 10) == 2)
{
printf("bravo! %i is the %ind number of the array! it's address is %p\n", key, i+1, &array[i]);
}
else if ((i+1 % 10) == 3)
{
printf("bravo! %i is the %ird number of the array! it's address is %p\n", key, i+1, &array[i]);
}
else
{
printf("bravo! %i is the %ith number of the array! it's address is %p\n", key, i+1, &array[i]);
}
return 1;
}
}