Write a C program that uses a function to take 5 integers fr

Write a C program that uses a function to take 5 integers from the user, store them in an array and display their average on the screen. Note that the main part of your program will just have a function call. No other components need to be there in the main part

Solution

// C code to input 5 numbers and determine average

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void average()
{
   int i;
   int array[5];
   int sum = 0;
   int size = 5;

   for (i = 0; i < 5; ++i)
   {
      printf(\"Enter integer %d: \", i+1);
      scanf(\"%d\",&array[i]);
      sum = sum + array[i];
   }

   double avg = sum/(double)(size);

   printf(\"\ Average: %lf\ \",avg);

}

int main()
{
   average();

   return 0;
}


/*
output:

Enter integer 1: 5
Enter integer 2: 6
Enter integer 3: 3
Enter integer 4: 6
Enter integer 5: 7

Average: 5.400000


*/

Write a C program that uses a function to take 5 integers from the user, store them in an array and display their average on the screen. Note that the main part

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site