Commit ca422b9e by ilahma

Upload New File

parent 35c19a20
Showing with 77 additions and 0 deletions
#include <stdio.h>
float average(int array[], float count);
int max(int array[], int n);
int min(int array[], int n);
int main() {
int number;
int i;
int array[number];
char operator;
printf(" How long is your array? \n");
scanf("%d", &number);
printf("Please, enter numbers \n");
for(i=0; i<number; i++) {
scanf("%d", &array[i]);
}
while(getc(stdin) != '\n'); // scanf function takes /n as a character
printf("Please, enter an operator: average (a), max (l) or min (s) \n");
scanf("%c", &operator);
switch(operator)
{
case 'a':
printf("Average is %.1f", average(array, number));
break;
case 'l':
printf("Max number is %d" ,max(array,number));
break;
case 's':
printf("Min is %d ",min(array,number));
break;
case '\n':
puts("dickdickdick");
default:
printf("Operator is not correct");
}
return 0;
}
float average(int array[], float count){
float sum =0;
int i;
for(i=0; i<count; i++){
sum=sum+array[i];
}
return sum/count;
}
int max(int array[], int n){
int max =array[0];
int i;
for (i = 1; i < n; i++)
if (array[i] > max)
max = array[i];
return max;
}
int min(int array[], int n){
int min =array[0];
int i;
for (i = 1; i < n; i++)
if (array[i] < min)
min = array[i];
return min;
}
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