Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <conio.h>
- void saveInFile(float *X,int S)
- {
- int i;
- FILE *cfPtr;
- if((cfPtr=fopen("arrayInF.txt","w"))==NULL)
- printf("File could not be opened\n");
- else
- {
- fprintf(cfPtr,"%d\n",S);
- for (i=0;i<S;i++)
- {
- fprintf(cfPtr,"%f\n",X[i],i);
- }
- }
- fclose(cfPtr);
- }
- void readF(float *X, int R)
- {
- int i;
- FILE *fp;
- if((fp=fopen("arrayInF.txt","rt"))==NULL)
- printf("File could not be open\n");
- else
- {
- fscanf(fp,"%d",&R);
- printf("%d\n",R);
- for(i=0;i<R;i++)
- {
- fscanf(fp,"%f",&X,&i);
- printf("%f\n",X,i);
- }
- }
- }
- float minp(float x[],int size)
- {
- float min;
- int i;
- min=x[0];
- for(i=0;i<size;i++)
- {
- if (((x[i]<min) || (min<0)) && (x[i]>=0)) min=x[i];
- }
- return min;
- }
- void input_array(float x[], int size)
- {
- int i;
- printf("Input %d float numbers.\n",size);
- for(i=0;i<size;i++)
- {
- printf("x[%d]=",i+1);
- scanf("%f",&x[i]);
- }
- }
- int main(void)
- {
- float *x,min;
- int s;
- srand(time(NULL));
- s=10-rand()%5;
- x=(float *) malloc(sizeof(float)*s);
- input_array(x,s);
- saveInFile(x,s);
- readF(x,s);
- min=minp(x,s);
- if (min>=0) printf("Min=%f\n",min);
- else
- {
- printf("Vse chisla otricatel`nie\n");
- }
- free(x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement