Here's my solution. It took me an embarrassing amount of time, not having used C for several years.
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char buf[16];
char *d[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
char *errmsg = "", *p;
int i, ncon, maxcon=0, bestday=0;
do
{
printf("%sEnter an integer in range 1-7: ", errmsg);
fgets(buf, sizeof(buf), stdin);
i=atoi(buf);
/* error message never displays if first input is ok */
errmsg="Invalid input, try again.\n";
}
while (i<1 || i>7);
printf("Corresponding day is %s\n", d[i-1]);
for (i=0; i<7; i++)
{
ncon=0;
p=d[i];
while (*p)
{
if (strchr("AEIOU", toupper(*p)) == NULL)
ncon++;
p++;
}
if (ncon > maxcon)
{
maxcon = ncon;
bestday = i;
}
}
strcpy(buf, d[bestday]);
puts(strrev(buf));
return(0);
}
Actually, no single day has the most consonants, as Wednesday and Thursday both have the same number.