Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <stdio.

h>

//declaring data types


int num;
float total;
int arr[100];

//function definition
void largest()
{
//getting the elements from the user
printf("Enter the number of values to be stored in array : \n");
scanf("%d",&num);
printf("Input 5 elements in the array : \n");

for (int i=0; i<num; i++)


{
printf("element - %d :", i);
scanf("%d", &arr[i]);
}
//finding the maximum using array
int max = arr[0];
for(int i = 0; i < num; i++)
{
if (arr[i] > max )
{
max = arr[i];
}
}
printf("The largest element in the array is: %d\n",max);
}

void average()
{
//finding the average of values in array
for( int i = 0; i < num; i++)
{
total = total + arr[i];
}
printf("The average is: %.2f\n",total /(float)num);
}

int main()
{
//function calling
largest();
average();
return 0;
}

You might also like