Question

C code that receives a list of integer numbers separated by space and terminated by EOF...

C code that receives a list of integer numbers separated by space and terminated by EOF as input and output the mean of the non-duplicated elements with 2 decimal points precision. The algorithm should be at most O(n log n). In your write up, describe the pseudocode and the complexity

e.g 2 -2.5 3 2.5 3 EOF

output: 1.25

Note do not include anything other than <stdio.h>

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Algo sumco file; . n= Take input from while (n!= EOF) { sumurn; natake input from file; ? point (mean =%d, swm/mo: of eleme

code:-

#include <stdio.h>
int main(void){
   int n,i;
   printf("Enter number of inputs:");
   scanf("%d",&n);
    float array[n],mean=0;
    printf("Enter inputs:");
    for (i=0;i<n;i++){
       scanf("%f",&array[i]);
       mean=mean+array[i];       //It won't matter if we include duplicate values too,the result will be same
    }
    printf("Result mean=%.2f",mean/n);
    return 0;
}

output:-

C:\Program Files (x86)\Dev-Cpp ConsolePauser.exe Enter number of inputs:5 Enter inputs:1.1 1.1 3.4 3.4 5 Result mean=2.80 Pro

thank you

Add a comment
Know the answer?
Add Answer to:
C code that receives a list of integer numbers separated by space and terminated by EOF...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to...

    The Sieve of Eratosthenes is a simple, ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking as composite lie., not prime) the multiples of each prime, starting with the multiples of 2 The sieve of Eratosthenes can be expressed in pseudocode, as follows: Input: an integer n Let A be an array of 8oo1ean values, indexed by integers 2 to n, initially all set to true. for t - 2, 3,...

  • 1. Prepare C++ code that prompts the user for an input integer n, creates a vector...

    1. Prepare C++ code that prompts the user for an input integer n, creates a vector consisting of numbers 0,1,2,…,n-1, runs the STL algorithm random_shuffle on it and then prints out the resulting outcome, i.e. the resulting random permutation. 2. Prepare C++ code that prompts the user for an input integer n, creates a vector consisting of numbers 0,1,2,…,n-1, runs the STL algorithm random_shuffle on it and creates three copies of the resulting outcome (probably 3 .txt files).

  • The input consists of n numbers a1, a2, . . . , an and a target...

    The input consists of n numbers a1, a2, . . . , an and a target value t. The goal is to determine in how many possible ways can we add up two of these numbers to get t. Formally, your program needs to find the number of pairs of indices i, j, i < j such that ai+aj = t. For example, for 2, 7, 3, 1, 5, 6 and t = 7, we can get t in two...

  • Consider an input file A2.txt. Each line of A2.txt consists of two numbers separated by space....

    Consider an input file A2.txt. Each line of A2.txt consists of two numbers separated by space. Write a C++ program that reads the two numbers from each line and prints how many numbers are prime between them. Your program must have a user defined function that takes one number as input parameter and detects whether its prime or not. Show your output in a file named B2.txt using the following format: Sample Input: 3 17 42 91 Sample Output: 6...

  • Please Help ASAP. 1Consider the below code which iterates over a linked list of n nodes...

    Please Help ASAP. 1Consider the below code which iterates over a linked list of n nodes (assume the list has at least 1 node). How many lines of output will it write? Node *thisNode = headPtr; while (thisNode != null) { cout << thisNode->item << endl; thisNode = thisNode->next; } 1.n 2.1 3.n2 4.n / 2 5.2 * n 2The below algorithm contains nested loops.   for (int total = 1; total <= n; total++) { for (int samples = 0;...

  • programing C,already write part of code (a) Write a function print.array that receives an array of...

    programing C,already write part of code (a) Write a function print.array that receives an array of real numbers and the number of el stored in the array. This function must display the elements of the array in order with each one on a line by itself in a field width of 7 with two decimal places. (See sample output. Recall the format specifier would be "%7.21f"). (b) Sometimes we want to treat an array as a mathematical vector and compute...

  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • Code in C An integer is divisible by 9 if the sum of its digits is...

    Code in C An integer is divisible by 9 if the sum of its digits is divisibleExample output: by 9. Develop a program which will call UDF: int get input(); to prompt the user for an integer and return this user input to main() Call UDF: Enter an integer: 5463 3 4 5 5463 is divisible by 9 void display int val); to display each digit of the integer starting with the rightmost digit. Your program should also determine whether...

  • Java question Given an array of integer numbers, write a linear running time complexity program in...

    Java question Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array. For an array A consisting n integers elements, index i is a stability index in A itf ATO] + A[1] + +A[iI-1] Ali+1]+ Ali+2] +... + A[n-1]; where 0 <i< n-1 Similarly, 0 is an stability index if (A[1] A[2]A[n-1]) 0 and n-1 is an stability index if (A[0] A[1]+... A[n-21) 0 Example:...

  • Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231...

    Please solve using Java and comment your code for clarity. Sample 3. Input: 4 1 231 Output: 0 This sequence also does not have a majority element (note that the element 1 appears twice and hence is not a majority element). Problem Introduction Majority rule is a decision rule that selects the alternative which has a majority, that is, more than half the votes. Given a sequence of elements (1.02....,On, you would like to check whether it contains an element...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT