Question

In: Computer Science

Design, code, and test a program that accepts positive integers until the value 204 is entered....

Design, code, and test a program that accepts positive integers until the value 204 is entered. After input terminates, the program should report the total number of even integers (excluding the special number 204) , the average value of the even integers, the total number of odd integers, and the average value of the odd integers. The program should also report "Evens won!", "Odds won!", or "Evens and odds tied!" based on which total was greater. Test your program thoroughly and submit output with at least twelve (12) integers as input.

Please write in a C program.

Solutions

Expert Solution

C code:

#include <stdio.h>
int main()
{
    //initializing even and odd number sum, even and odd number count
    float even=0,odd=0,even_count=0,odd_count=0,num;
    //accepting number
    scanf("%f",&num);
    //looping till 204 is entered
    while((int)num!=204){
        //checking if the number is even
        if((int)num%2==0){
            //adding it to even
            even+=num;
            //incrementing even_count
            even_count++;
        }
        else{
            //adding it to odd
            odd+=num;
            //incrementing odd_count
            odd_count++;
        }
        //accepting number
        scanf("%f",&num);
    }
    //printing Total number of even integers
    printf("Total number of even integers: %d\n",(int)even_count);
    //printing Average value of even integers
    printf("Average value of even integers: %.2f\n",even/even_count);
    //printing Total number of odd integers
    printf("Total number of odd integers: %d\n",(int)odd_count);
    //printing Average value of odd integers
    printf("Average value of odd integers: %.2f\n",odd/odd_count);
    //checking if Average of even values is greater
    if(even/even_count>odd/odd_count)
    //printing Evens won
        printf("Evens won!");
    //checking if Average of odd values is greater
    else if(even/even_count<odd/odd_count)
    //printing Odds won
        printf("Odds won!");
    else
    //printing Evens and odds tied
        printf("Evens and odds tied!");
    return 0;
}


Screenshot:


Input and Output:


Related Solutions

Write a C++ program that accepts a single integer value entered by user. If the value...
Write a C++ program that accepts a single integer value entered by user. If the value entered is less than one the program prints nothing. If the user enters a positive integer n. The program prints n x n box drawn with * characters. If the user enters 1 , for example the program prints *. If the user enter a 2, it prints ** ** that is , a 2x2 box of * symbols.
java Problem 3: An Interesting Problem Write a program that accepts two positive integers: a deposited...
java Problem 3: An Interesting Problem Write a program that accepts two positive integers: a deposited amount of money and an interest rate, as an annual percentage rate. Your program will calculate the number of years that will take for the account balance to reach $1, 000,000. You can assume that the initial deposit is less than $1,000,000 Input The input will begin with a single line containing T , the number of test cases to follow. The remaining lines...
Do not use arrays and code a program that reads a sequence of positive integers from...
Do not use arrays and code a program that reads a sequence of positive integers from the keyboard and finds the largest and the smallest of them along with their number of occurrences. The user enters zero to terminate the input. If the user enters a negative number, the program displays an error and continues. Sample 1: Enter numbers: 3 2 6 2 2 6 6 6 5 6 0 Largest Occurrences Smallest Occurrences 6 5 2 3. Do not...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the...
Write a complete MiniMIPS program that accepts a seqeunce of integers at input and after the receipt of each new input value, displays the largest and smallest integers thus far. An input of 0 indicates the end of input values and is not an input value itself. Note that you do not need to keep all integers in memory.
C ++ code that accepts any measurement in meters entered by the user through the keyboard...
C ++ code that accepts any measurement in meters entered by the user through the keyboard and displays the equivalent measurement in feet on the console (1 Meters = 3.2808 Feet). Use proper variable names.
In javascript, make a program that takes in a positive integer (entered on a textbox and...
In javascript, make a program that takes in a positive integer (entered on a textbox and submitted by clicking a button). Then, it displays the sum of all the integers between that number and zero. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script> function add(n) {    /*This function MUST USE RECURSION to do the sum of the numbers.*/ } function check() {    /*This function takes the input entered and checks if it's an integer. If it's not a number, it should...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain...
specifications for Tasks: 1. Write a program which accepts a list of integers which may contain duplicated integers, and which outputs the input list as a sorted list in ascending order without duplication You can use either Ruby, C, C++, C# or Java to implement your program (referred to as P). 2. Design a test suite of 10 test cases (referred to as TC). Each test case has not more than 20 integers. 3. Test P against TC to make...
Implement and complement the recursive code to compute the product of two positive integers, x and...
Implement and complement the recursive code to compute the product of two positive integers, x and y, using only addition and/or subtraction. The function will take as its arguments two integers to multiply together ( x x y ) and will return the product. Hint: consider the following: 6 x 1 = 6 6 x 2 = 6 + (6 x 1) 6 x 3 = 6 + (6 x 2) = 6 + [6 + (6 x 1)] =...
In Java: Write a program that prompts the user to enter a positive number until the...
In Java: Write a program that prompts the user to enter a positive number until the user input a negative number. In the end, the program outputs the sum of all the positive numbers. You should use do-while loop (not while, not for). You cannot use break or if statement in the lab. Hint: if the program adds the last negative number to your sum, you can subtract the last number from the sum after the loop.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT