Commit d6a23ad0 by viakul

Upload New File

parent 1e96b564
Showing with 98 additions and 0 deletions
#include <stdio.h>
float average(int* x,int y);
int max(int* x,int y);
int min(int* x,int y);
int main()
{
int choice,n,i;
float result;
i = 0;
puts("write the number of values in array");
scanf("%d", &n);
int ThisArray[n];
puts("the first element is array");
while(i<n){
scanf("%d", &ThisArray[i]);
i=i+1;
if (i<n){
printf("print another number\n");
}
}
printf("thank you for numbers\n");
printf("\n");
printf("\n");
puts("What do you want to do with numbers?");
puts("for average write 1 ");
puts("for max write 2 ");
puts("for min write 3 ");
do{
puts("make a choice ");
scanf("%d", &choice);
}while(choice < 1 || choice > 4);
switch(choice){
case 1:
result=average(ThisArray,n);
break;
case 2:
result=max(ThisArray,n);
break;
case 3:
result=min(ThisArray,n);
break;
}
printf("%f",result);
return 0;
}
float average(int* x,int y){
int sum,i;
float avg;
i=0;
sum=0;
while(i<y){
sum=sum+x[i];
i=i+1;
}
avg=sum/y;
return(avg);
}
int max(int* x,int y){
int maxVal,i;
maxVal=x[0];
i=1;
while(i<y){
if (maxVal<x[i])
{
maxVal=x[i];
}
i=i+1;
}
return(maxVal);
}
int min(int* x,int y){
int maxVal,i;
maxVal=x[0];
i=1;
while(i<y){
if (maxVal > x[i])
{
maxVal=x[i];
}
i=i+1;
}
return(maxVal);
}
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