C: Reading multiple areas into an array and finding the largest value -


i'm attempting find largest value in array. i'm given set of areas (the input), is:

4.5 19.59 1.92 

these areas need read array using scanf , there need find largest value (area) in array. should known there can maximum of 100 areas can read array. later on may need read in 5 or 20 or 99 etc... array.

if give me hand it'd appreciated, i'm new programming , don't know begin.

you have said in comment data redirected file. have said need find biggest value. in case, eof indication used denote end of input. also, don't need store values.

you need read values 1 one, storing largest one. see below code:

file* fp = fopen(filename,"r"); if(fp == null)    handle_error(); // or exit(0);  double largest=0,temp; while( (fscanf(fp, "%lf", &temp) == 1) {     if( temp > largest)         largest = temp; }  printf("largest area = %f" , largest); 

the while loop break when

  1. the end of file(eof) encountered
  2. any invalid data(like characters) found

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -