my programm should calculate many values of a variable that changes in a while loop, store theses values in an Array and then search the maximum value.
the problem i faced is that the values are not stored, when the loop is incremented, the new calculted value crush the precedent one and then how can i compare them?
I just know scanf to store but it doesn't work in this case, should i use another pointer to go over the array values???
//// Simple Program to explain the problem!!!
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
float *tab;
int main()
{
float a;
a=-1;
int i;
float tab[maxi]=0;
int taille=10;
for (i=0;i<taille; i++)
{
while (a < 30)
{
float s= -a*a+a+1;
tab=(float(*)) malloc(taille*sizeof (float));
tab[i]=s;
if(tab[i]>= tab[maxi])
{
maxi=tab[i];
printf("\n maxi=%f",maxi);
break;
}
a=a+1;
}
}
return 0;
}
thanks in advance!