Question

In: Computer Science

Martin wants to create a program that requires the user to input 10 integers then print...

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 :

Solutions

Expert Solution


#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;
}


Related Solutions

Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
Create a program to input the length and width of a rectangle and calculate and print...
Create a program to input the length and width of a rectangle and calculate and print the perimeter and area of the rectangle. To do this you will need to write a Rectangle class and a separate runner class. Your program should include instance variables, constructors, an area method, a perimeter method, a toString method, accessor and mutator methods, and user input. Your runner class should include 3 Rectangle objects. One default rectangle, one coded rectangle, and one user input...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
You are to create a program to request user input and store the data in an...
You are to create a program to request user input and store the data in an array of structures, and then display the data as requested. The data you are collecting refers to a set of images. The images are OCT images taken of the lining of the bladder. The data you provide will help diagnose the image as cancerous or not, but your code does not need to do that at the moment. First, Define a global structure that...
write a program named Combinations.java that gets user input for two integers n and k, then...
write a program named Combinations.java that gets user input for two integers n and k, then computes and displays the value of n choose k using the efficient method of equation. you may assume that the user's input makes sense (i.e, n and k are non negative, and n is at least k). your code should work for any reasonably small non- negative values of n and k, including zero.
Read three integers from user input.
Read three integers from user input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT