title: I'd like to know why the result of the average of array always wrong
body: <p>(I want to write a code to calculate the sum and average of the elements of an array)
  I wanted to find out the reason for the wrong average result where the average might be float so I made the cast to convert the result to float using <code>(float)sum)/size</code>.</p>
  
  <p><strong>NOTE</strong>: I know if I definite variable average this problem will be solved</p>
  
  <pre class="lang-c prettyprint-override"><code>float average = (float)sum/arr_size;
  printf("The average of the array elements is: %f\n", average);
  </code></pre>
  
  <p>But I need analysis of my wrong output of average  </p>
  
  <pre class="lang-c prettyprint-override"><code>#include&lt;stdio.h&gt;
  #define size 5
  int main(void)
  { 
    int i,sum=0;
    int arr[size];
    printf("please enter array elements: \n");
    // for loop to scant element elemnt of array
    for(i=0;i&lt;size;i++)
    {
        scanf("%d",&amp;arr[i]);
    }
    // sum of array
    for(i=0;i&lt;size;i++)
    {
        sum+=arr[i];
    }
    // print sum after fishing
    printf("the summation is : %d \n",sum);
  
    // average of array
    printf("The average of array : %d",(((float)sum)/size));
  
    return 0;
  }
  </code></pre>