Commit 890c94e3 by matjul

Upload New File

parent 99399728
Showing with 106 additions and 0 deletions
#include <stdio.h>
float ave(int array[], int numbers);
int max(int array[], int numbers);
int min(int array[], int numbers);
int main(){
int i;
int numbers;
int choice;
int result;
float resultf;
puts("Enter the amount of numbers");
scanf("%d", &numbers);
int array[numbers];
puts("Enter the numbers");
for(i = 0; i < numbers; i++){
scanf("%d", &array[i]);
}
printf("The action with numbers:\n1 - average\n2 - max\n3 - min\n");
do{
puts("pick the numbers");
scanf("%d", &choice);
}
while(choice < 1 || choice > 3);
switch(choice){
case 1:
puts("The average thing");
resultf = ave(array, numbers);
printf("%f", resultf);
break;
case 2:
puts("The maximum thing");
result = max(array, numbers);
printf("%d", result);
break;
case 3:
puts("The minimum thing");
result = min(array, numbers);
printf("%d", result);
break;
}
return 0;
}
float ave(int array[], int numbers){
float A = 0;
int i;
for(i = 0; i < numbers; i++){
A += array[i];
}
A = A / numbers;
return A;
}
int max(int array[], int numbers){
int B = 0;
int i = 1;
int tmp = 0;
tmp = array[0];
for(i = 1; i < numbers; i++){
if(tmp < array[i]){
tmp = array[i];
}
}
B = tmp;
return B;
}
int min(int array[], int numbers){
int C = 0;
int i = 1;
int tmp = 0;
tmp = array[0];
for(i = 1; i < numbers; i++){
if(tmp > array[i]){
tmp = array[i];
}
}
C = tmp;
return C;
}
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