In: Computer Science
Martin wants to create a program that requires the
user to input 10 integers then print the total number of even
integers, highest even integer, lowest even integer, total number
of odd integers, highest odd integer, and lowest odd integer. If,
however, the user inputs zero (0), the program will display “You
have not yet entered 10 integers.”
Below is the sample output of the program Martin created.
Enter the integers:
Integer 1: 15
Integer 2: 9
Integer 3: 71
Integer 4: 35
Integer 5: 17
Integer 6: 13
Integer 7: 63
Integer 8: 33
Integer 9: 97
Integer 10: 13
Total number of even integers : 0
Highest even integer : none
Lowest even integer : none
Total number of odd integers : 10
Highest odd integer : 97
Lowest odd integer :
#include <stdio.h>
int main()
{
int n=0, arr[10],val=0,i=0,counter=0,cnt=0;
int
min_even,max_even,min_odd,max_odd,Even_Count,sum_even,Odd_Count,sum_odd;
for(;;)
{
printf("\nEnter a number\n");
scanf("%d",&val);
counter++;
if(val!=0)
{
arr[i]=val;
i++;
}
if(val==0)
cnt++;
if(counter==10 && i<10)
{
printf("You have not yet entered 10 integers.");
counter=counter-cnt;
continue;
}
else if(counter==10 && i==10)
break;
}
min_even=min_odd=35535;
max_even=max_odd=0;
for(i = 0; i < counter; i ++)
{
if(arr[i] % 2 == 0)
{
Even_Count++;
sum_even=sum_even+arr[i];
if(min_even>arr[i])
min_even=arr[i];
if(max_even<arr[i])
max_even=arr[i];
}
else
{
Odd_Count++;
sum_odd=sum_odd+arr[i];
if(min_odd>arr[i])
min_odd=arr[i];
if(max_odd<arr[i])
max_odd=arr[i];
}
}
printf("Total number of even integers : %d\n",Even_Count);
if(Even_Count==0)
{
printf("Highest even integer : none\n");
printf("Lowest even integer : none\n");
}
else
{
printf("Highest even integer : %d\n",max_even);
printf("Lowest even integer : %d\n",min_even);
}
printf("Total number of odd integers : %d\n",Odd_Count);
if(Odd_Count==0)
{
printf("Highest odd integer : none \n");
printf("Lowest odd integer : none \n");
}
else
{
printf("Highest odd integer : %d\n",max_odd);
printf("Lowest odd integer : %d\n",min_odd);
}
return 0;
}