Saturday, September 22, 2018

Simple Array

  • Problem Description

    Calculate average of n numbers
  • CODING ARENA
  • #include<stdio.h>
    int main()
    {
      int a,b[100],c=0,i;
      scanf("%d",&a);
      for(i=0;i<a;i++)
      {
        scanf("%d",&b[i]);
        c=c+b[i];
      }
      printf("%d",c/a);
        return 0;
    }
  • Test Case 1

    Input (stdin)
    5 1 2 3 4 5
    
    
    Expected Output
    3
  • Test Case 2

    Input (stdin)
    3 1 2 3
    
    
    Expected Output
    2

No comments:

Post a Comment