Write a function which accepts an array of size n containing integer values and returns the average of all values. Call the function from main program.
#include <stdio.h>
#include <conio.h>
float arravg ( int [], int );
void main ( )
{
int arr[10], i;
float f;
clrscr ( );
for( i = 0; i < 10; i++ )
{
printf("\n\t\t Enter a number..:"); scanf("%d",&arr[i] );
}
f = arravg ( arr, 10 );
printf("\n\n\n\t\t Average of the array elements = %.2f",f);
getch ( );
}
float arravg ( int arr[], int l )
{
int i, s = 0;
float avg;
for ( i = 0; i < l; i++ )
{
s = s + arr[i];
}
avg = ( float ) s / l;
return avg;
}
Click here to contact us
#include <stdio.h>
#include <conio.h>
float arravg ( int [], int );
void main ( )
{
int arr[10], i;
float f;
clrscr ( );
for( i = 0; i < 10; i++ )
{
printf("\n\t\t Enter a number..:"); scanf("%d",&arr[i] );
}
f = arravg ( arr, 10 );
printf("\n\n\n\t\t Average of the array elements = %.2f",f);
getch ( );
}
float arravg ( int arr[], int l )
{
int i, s = 0;
float avg;
for ( i = 0; i < l; i++ )
{
s = s + arr[i];
}
avg = ( float ) s / l;
return avg;
}
Click here to contact us
No comments:
Post a Comment