Commit 5378d838 by chazog

Upload New File

parent 62abf84d
Showing with 99 additions and 0 deletions
#include <stdio.h>
#include <math.h>
float average(int array[], float size);
int maximum(int array[], int size);
int minimum(int array[], int size);
int main()
{
int i;
float ave;
int size;
int min;
int max;
int op;
printf("Enter the size of array: ");
scanf("%d", &size);
int array[size];
printf("enter the elements of array: ");
while (i < size)
{
scanf("%d", &array[i]);
i++;
}
printf("1.Average\n2.Minimum\n3.maximum\n");
scanf("%d", &op);
switch (op)
{
case 1:
ave = average(array, size);
printf("%f", ave);
break;
case 2:
min = minimum(array, size);
printf("%d", min);
break;
case 3:
max = maximum(array, size);
printf("%d", max);
break;
default:
printf(" Enter Your Correct Choice.");
break;
}
return 0;
}
float average(int array[], float size)
{
float ave = array[0];
int i = 0, sum = 0;
while (i < size)
{
sum = sum + array[i];
i++;
}
ave = sum / size;
return ave;
}
int minimum(int array[], int size)
{
int min = array[0];
int i = 1;
while (i < size)
{
if (array[i] < min)
{
min = array[i];
}
i++;
}
return min;
}
int maximum(int array[], int size)
{
int max = array[0];
int i = 1;
while (i < size)
{
if (array[i] > max)
{
max = array[i];
}
i++;
}
return max;
}
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