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 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...
Write a C program that prompts the user to input as many unsigned(n) as the user...
Write a C program that prompts the user to input as many unsigned(n) as the user wants to type, terminated by non negative number You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a double You may assume without checking that when the user is supposed to type an unsigned, he nevertypes a negative number. For each number the user types, output whether that number is prime or not. You won't need...
For any integer n > 0, n!(n factorial) is defined as the product n * n...
For any integer n > 0, n!(n factorial) is defined as the product n * n - 1 * n − 2 … * 2 * 1. And 0! is defined to be 1 Create function that takes n as input and computes then returns the accurate value for: n!= n * n - 1 * n − 2 … * 2 * 1 prompt the user to enter an integer n, call functions to compute the accurate value for...
USE ONLY C LANGUAGE The program should read inputs that look like this: 10 11 56...
USE ONLY C LANGUAGE The program should read inputs that look like this: 10 11 56 92 10 5 42 7 1 33 99 The program should start by reading one integer, which indicates how many numbers there are in the random sequence. The program should then read a sequence of random integers. If fewer numbers are provided than specified (by the first integer on the first line), the program should print the following error message (replace XXX with the...
1)Write a program that asks a user for a number. If (and only if) the number...
1)Write a program that asks a user for a number. If (and only if) the number is greater than zero print “The number is valid” 2)Write a program that asks a user for a grade. If (and only if) the grade is greater than zero and less than 101, print “The grade is valid” 3)Write a program that asks a user how many widgets they want to buy and prints out what the user should pay. Widgets costs 10 dollars....
1. Give a direct proof that the product of two odd integers is odd. 2. Give...
1. Give a direct proof that the product of two odd integers is odd. 2. Give an indirect proof that if 2n 3 + 3n + 4 is odd, then n is odd. 3. Give a proof by contradiction that if 2n 3 + 3n + 4 is odd, then n is odd. Hint: Your proofs for problems 2 and 3 should be different even though your proving the same theorem. 4. Give a counter example to the proposition: Every...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into...
Question 2: Write a C program that read 100 integers from the attached file (integers.txt) into an array and copy the integers from the array into a Binary Search Tree (BST). The program prints out the following: The number of comparisons made to search for a given integer in the BST And The number of comparisons made to search for the same integer in the array Question 3 Run the program developed in Question 2 ten times. The given values...
Write a C++ program to find least common multiple (LCM) of two, three and four integer...
Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the console, calculate LCM using Prime factorization method. Your program should...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or...
An integer 'n' greater than 1 is prime if its only positive divisor is 1 or itself. For example, 2, 3, 5, and 7 are prime numbers, but 4, 6, 8, and 9 are not. Write a python program that defines a function isPrime (number) with the following header: def isPrime (number): that checks whether a number is prime or not. Use that function in your main program to count the number of prime numbers that are less than 5000....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT