# Untitled

unknown
plain_text
2 months ago
1.8 kB
32
Indexable
Never
```#include <stdio.h>

int median(int k[],int n);
int mode(int k[],int n);

double mean(int k[],int n);

int main()
{
int n,temp;
scanf("%d",&n);
double sum=0;
int k[n];
///Input of the array
for(int i=0;i<n;i++){
scanf("%d",&k[i]);
}
///Output of the array
printf("The array is : \n");
for(int i=0;i<n;i++)
{
printf("%d ",k[i]);
}
printf("\n");
///Mean
double me=mean( k,n);
printf("The mean is : %lf\n",me);

///median
int media=median(k,n);
printf("The median is : %d",media);

///mode
int mo=mode(k,n);
printf("The mode is %d\n",mo);

return 0;
}

int median(int k[],int n)
{
int temp;
for(int i=0;i<n;i++){
for(int j=0;j<n-1;j++)
{
if(k[j]>k[j+1]){
temp=k[j];
k[j]=k[j+1];
k[j+1]=temp;
}
}
}
printf("The sorted array is :");
for(int i=0;i<n;i++){
printf("%d ",k[i]);
}
printf("\n");
if(n%2 != 0){
return k[n/2];
}

else{
int re=(k[n/2-1]+k[n/2]);
return re;
}

}
int mode(int k[],int n)
{
for(int i=0;i<n;i++){
for(int j=0;j<n-1;j++)
{
if(k[j]>k[j+1]){
temp=k[j];
k[j]=k[j+1];
k[j+1]=temp;
}
}
}
int cnt=1,max=-1;
for(int i=0;i<n;i++)
{
if(k[i]==k[i+1])
{
cnt++;
}
else{
if(cnt>max)
{
max=cnt;
cnt=1;
}
}
}
}

double mean(int k[],int n)
{
double sum=0;
for(int i=0;i<n;i++){
sum=sum+k[i];
}
return sum/n;
}```