Sunday, September 23, 2018

Array Mean

  • Problem Description

    Write a program to find the mean of the elements in the array.


    Input and Output Format:

    Input consists of n+1 integers where n corresponds to the number of elements in the array.

    The first integer corresponds to n and the next n integers correspond to the elements in the array.

    Output consists of a double value which corresponds to the mean of the array. It is printed upto 2 digits of precision.

    Assume that the maximum number of elements in the array is 20.

    Refer sample input and output for formatting specifications.

    All text in bold corresponds to input and the rest corresponds to output.
  • CODING ARENA
  •   #include<stdio.h>
    int main(){
      int n, a[20], i;
      float min=0;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      {
        scanf("%d",&a[i]);  
        min+=a[i];
      }

      printf("The mean of the array is %.2f",min/n);
      return 0;
    }
  • Case 1

    Input (stdin)
    5
    
    2
    
    4
    
    1
    
    3
    
    5
    
    
    Expected Output
    The mean of the array is 3.00
  • Test Case 2

    Input (stdin)
    10
    
    100
    
    105
    
    200
    
    205
    
    108
    
    15
    
    18
    
    88
    
    1000
    
    12
    
    
    Expected Output
    The mean of the array is 185.10

No comments:

Post a Comment