Code:
#include <stdio.h>
#include <string.h>
int main (void)
{
char max='\0', min='\0'; /* Initalized them to characters thate the user can't input */
int len, count;
char buff[20];
scanf("%s", buff);
len = strlen(buff); /* How long is the string */
for (count=0; count<len; count++) /* Step through the string */
{
if ( buff[count] < '1' || buff[count] > '9') /* If the characters are not between 1 and 9 then skip them */
continue;
if (max == '\0')
{
max = min = buff[count]; /* if max is still the inital value then assign the character to min and then to max */
continue; /* skip the rest of the loop and go on to next character */
}
if ( max < buff[count] ) /* If max is lower then the character its no longer the max */
max = buff[count];
if ( min > buff[count] ) /* if min is greater then the character its no longer the min */
min = buff[count];
}
printf("The max and min of %s is %c and %c\n", buff, max, min);
return 0;
}