ENSO code

#include <stdio.h>
#include <math.h>

#define FILENAME "ENSO1.txt"

#define MAX_SIZE 1000

int main(void)

{

/* Declare variables and function prototypes. */

int k=0, year[MAX_SIZE], qtr[MAX_SIZE], max_k=0, min_k = 0, zero_k=0;

double index[MAX_SIZE];

FILE *enso;

/* Read sensor data file. */

enso = fopen(FILENAME,"r");

if (enso == NULL)

printf("Error opening input file. \n");

else

{

while (fscanf(enso,"%d %d %lf",

year+k,qtr+k,index+k)==3)

{

if (*(index+k) > *(index+max_k)){

max_k = k;
}

if(*(index+k) < *(index+min_k)){
min_k = k;

}
if(fabs(*(index+k)) < fabs(*(index+min_k))){
zero_k = k;

}
k++;
}

/* Print data for maximum El Nino condition. */

printf("Maximum El Nino Conditions in Data File \n");

printf("Year: %d, Quarter: %d \n",*(year+max_k),*(qtr+max_k));
printf("Maximum El Nina Conditions in Data File \n");

printf("Year: %d, Quarter: %d \n",*(year+min_k),*(qtr+min_k));
printf("Closest to Zero in Data File \n");

printf("Year: %d, Quarter: %d \n",*(year+zero_k),*(qtr+zero_k));
/* Close file. */

fclose(enso);

}

/* Exit program. */

return 0;

}


Comments

Popular posts from this blog

Seismic Code

Strings

BMP180 Code + Library to SD card