mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-24 14:29:42 +03:00
18 Oct
This commit is contained in:
parent
d4bc8cd8d6
commit
9c3f920403
46
Computer Oriented Statistical Methods/MEAN.C
Normal file
46
Computer Oriented Statistical Methods/MEAN.C
Normal file
@ -0,0 +1,46 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
{
|
||||
int a[10],n,i,j,temp,sum=0;
|
||||
float mean;
|
||||
clrscr();
|
||||
printf("Enter no. for Random Numbers :");
|
||||
scanf("%d",&n);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
a[i]=rand()%100;
|
||||
}
|
||||
printf("Random Numbers Generated are :\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("\nSorted Data:");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
if(a[i]<a[j])
|
||||
{
|
||||
temp=a[i];
|
||||
a[i]=a[j];
|
||||
a[j]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
sum=sum+a[i];
|
||||
}
|
||||
mean=sum/(float)n;
|
||||
printf("\nMean :");
|
||||
printf("%f",mean);
|
||||
|
||||
getch();
|
||||
}
|
||||
|
||||
|
49
Computer Oriented Statistical Methods/MEDIAN.C
Normal file
49
Computer Oriented Statistical Methods/MEDIAN.C
Normal file
@ -0,0 +1,49 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#include<math.h>
|
||||
void main()
|
||||
{
|
||||
int a[10],n,i,j,temp;
|
||||
float mean,median;
|
||||
clrscr();
|
||||
printf("Enter no. for Random Numbers :");
|
||||
scanf("%d",&n);
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
a[i]=rand()%100;
|
||||
}
|
||||
printf("Random Numbers Generated are :\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("\nSorted Data:");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<n;j++)
|
||||
{
|
||||
if(a[i]<a[j])
|
||||
{
|
||||
temp=a[i];
|
||||
a[i]=a[j];
|
||||
a[j]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("\n%d",a[i]);
|
||||
}
|
||||
|
||||
if(n%2==0)
|
||||
{
|
||||
median=(a[n/2]+a[(n/2)-1])/2;
|
||||
}
|
||||
else
|
||||
{
|
||||
median=a[n/2];
|
||||
}
|
||||
printf("\nMedian is : %f",median);
|
||||
getch();
|
||||
}
|
Loading…
Reference in New Issue
Block a user