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...
(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
Read three integers from user input.
Read three integers from user input.
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT