Czemu w funckji void max "printf" wywołuje mi kilka liczb,a nie wartość jedną maksymalna oraz funkcja void reverse, ma mi odwracać kolejność w tablicy, a tego nie robi ?
Za udzielone wskazówki będę bardzo wdzięczny.
Kod: Zaznacz cały
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define n 20
void li (double t1[]);
void sr(double t1[]);
void od(double t1[]);
void max(double t1[]);
void reverse(double t1[]);
int main()
{
double t1[n];
li(t1);
sr(t1);
od(t1);
max(t1);
reverse(t1);
system("PAUSE");
return 0;
}
void li(double t1[])
{
srand(time(0));
for(int i=0; i<n; ++i)
{
t1[i]=(double)(rand() / (RAND_MAX + 1.0) * 1.0);
printf("numer indeksu %d wartosc = %lf
",i,t1[i]);
}
}
void sr(double t1[])
{
double sum;
sum=0;
for(int i=0;i<n;i++)
sum=sum+t1[i];
printf("srednia=%lf
",sum/n);
}
void od(double t1[])
{
double sum;
double os;
double s;
sum=0;
for (int i=0;i<n;i++)
{sum=sum+t1[i];}
s=sum/n;
sum=0;
for (int i=0;i<n;i++)
{sum=sum+(t1[i]-s)*(t1[i]-s);}
os=sqrt(sum/n);
printf("odchylenie standardowe=%lf
",os/n);
}
void max(double t1[])
{
double max_value;
int max_index;
max_value=t1[0];
max_index=0;
for(int i=0;i<n;i++)
{
if(t1[i] > max_value)
{
max_value=t1[i];
max_index=i;
printf("najwieksza wartosc = %lf
",max_value);
}
}
}
void reverse(double t1[])
{
double temp;
for(int i=0; i<n/2; i++)
{ t1[n-i-1]= t1[i];
temp = t1[n-i-1];
t1[i] = temp;
}
}