Question

IN C LANGUAGE This program initially reads two integers from standard input: (1) an integer T...

IN C LANGUAGE

This program initially reads two integers from standard input: (1) an integer T and (2) a positive integer N. It then reads N integers and counts the numbers that are greater than T and the numbers than are less than T. It then prints out these two counts.

Example

What is the threshold value?
7
How many values?
5
Enter 5 values:
6 7 9 9 8
3 values are greater than 7
1 values are less than 7

Notes

  • All input will be valid.
  • The grader is checking if your output ends with: "X values are greater than T" followed by "Y values are less than T"

Homework Answers

Answer #1
#include <stdio.h>

int main() {
    int threshold, i, n, greater = 0, less = 0, num;
    printf("What is the threshold value?\n");
    scanf("%d", &threshold);
    printf("How many values?\n");
    scanf("%d", &n);
    printf("Enter %d values:\n", n);
    for (i = 0; i < n; ++i) {
        scanf("%d", &num);
        if (num < threshold)
            less++;
        if (num > threshold)
            greater++;
    }
    printf("%d values are greater than %d\n", greater, threshold);
    printf("%d values are less than %d\n", less, threshold);
    return 0;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Write in C++) Write a program that reads in two numbers and, if the input is...
(Write in C++) Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop...
Write a program in C++ that reads integer values from standard input and writes to standard...
Write a program in C++ that reads integer values from standard input and writes to standard output the smallest of the inputs and the average input value. The program should stop reading when a value equal to -1 or greater than 100 is encountered. It should also stop when an incorrect integer value (i.e., anything that isn't an int) is entered. If there is not an integer value in the input, the program should output "no integers provided"
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input....
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input. The first integer indicates the number of values that will follow. Read that many values, and return their sum, ignoring any additional values that may follow. However, if there are fewer integers than specified in the input, print "Error" and terminate. Hint: int n, success; ... success = scanf("%d", &n); // FIRST INTEGER INPUT reads an integer from stdin, returning 1 if the integer...
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of...
(C++) 5.15 LAB: Two smallest numbers with arrays Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input begins with an integer indicating the number of integers that follow. Ex: If the input is: 5 10 5 3 21 2 the output is: 2 3 You can assume that the list of integers will have at least 2 values. To achieve the above, first read the integers...
write a in c++ program that reads in two integers from cin and outputs all of...
write a in c++ program that reads in two integers from cin and outputs all of the integers between those values, except powers of three. You can assume that the first value is strictly less than the second value If you were to enter 5 and 30 you would get 6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,28 so Iā€™m not sure how to get rid of the powers of 3, so 3^1, 3^2 ... etc
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between ā€“10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is -3 10...
This is an exercise using a while loop Input an integer n from the keyboard. Calculate...
This is an exercise using a while loop Input an integer n from the keyboard. Calculate the sum of the first n integers. So if n=10, the answer should be 55 (because 1+2+3+4+5+6+7+8+9+10=55) Code language: Java
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between ā€“10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...