Commit a53f4300 by emonyi

Upload New File

parent 5347fc53
Showing with 95 additions and 0 deletions
#include <stdio.h>
#include <math.h>
float average(int array[], float n);
int maximum(int array[], int n);
int minimum(int array[], int n);
int main()
{
int i;
float ave;
int n;
int small;
int big;
int output;
printf("Enter the size of array: ");
scanf("%d",&n);
int array[n];
printf("enter the elements of array: ");
while(i < n){
scanf("%d", &array[i]);
i++;
}
printf("Select a calculation; 1 for Average\n 2 for Minimum\n 3 for maximum\n");
scanf("%d",&output);
switch(output)
{
case 1 :
ave = average(array, n);
printf("%f", ave);
break;
case 2 :
small = minimum(array, n);
printf("%d", small);
break;
case 3 :
big = maximum(array, n);
printf("%d", big);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
return 0;
}
float average (int array[], float n){
float ave = array[0];
int i=0, sum = 0;
while(i < n){
sum = sum + array[i];
i++;
}
ave = sum / n;
return ave;
}
int minimum (int array[], int n){
int small = array[0];
int i=1;
while(i < n){
if (array[i] < small){
small = array[i];
}
i++;
}
return small;
}
int maximum (int array[], int n){
int big = array[0];
int i=1;
while(i < n){
if (array[i] > big){
big = array[i];
}
i++;
}
return big;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment