C

C Program To Find Average Of N Numbers Using For Loop

In this tutorial, we are going to see how to write a C program to find the average of N numbers using for loop.
 


 

C Program To Find Average Of N Numbers Using For Loop
#include <stdio.h>

int main() {
   int arr[7] = {9, 1, 5, 2, 3, 11, 6};
   int s = 0, i;
   float avg = 0;
   
   for(i = 0; i < 7; i++) {
      s = s + arr[i];
   }
   
   avg = (float)s / i;
   printf("The average of the array elements is %.2f", avg);   
   
   return 0;
}

Output:

The average of the array elements is 5.29

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *