Posts

Nothing on Day19

Another Day 17

Image
#include <stdio.h> #define FILENAME "storms2.txt" /* Define structure to represent a hurricane. */ struct hurricane { char name[10]; int year, category; }; int main(void) { /* Declare variables and function prototype. */ int max_category = 0, k = 0, npts; struct hurricane h[100]; FILE *storms; void print_hurricane(struct hurricane h); /* Read and print information from the file. */ storms = fopen(FILENAME, "r"); if (storms == NULL) printf("Error opening data file. \n"); else { printf("Hurricanes with Maximum Category \n"); while (fscanf(storms, "%s %d %d", h[k].name, &h[k].year, &h[k].category) == 3) { if (h[k].category > max_category) max_category = h[k].category; k++; } npts = k; for (k = 0; k <= npts - 1; k++) if (h[k].category == max_category) print_hurricane(h[k]); fclose(storms); } /* Exit program */ return 0; } /*??...

Day 18

Image
/* */ /* This program reads the information for a hurricane */ /* from a data file and then prints it, using a function. */ #include <stdio.h> #define FILENAME "storms2.txt" struct tsunami get_info(void); /* Define structure to represent a hurricane. */ struct hurricane { char name[10]; int year, category; }; int main(void) { /* Declare variables and function prototype. */ struct hurricane h1; FILE *storms; void print_hurricane(struct hurricane h); /* Read and print information from the file. */ storms = fopen(FILENAME,"r"); if (storms == NULL) printf("Error opening data file. \n"); else { while (fscanf(storms,"%s %d %d",h1.name,&h1.year,&h1.category) == 3) print_hurricane(h1); fclose (storms); } /* Exit program. */ return 0; } /* */ /* This function prints the hurricane information. */ void print_hurricane(struct hurricane h) { printf("Hurricane: %s \n",h.name); printf("Year: %d, ...

Day 17

Image
Homework: /* This program reads a seismic data file and then */ /* determines the times of possible seismic events. */ #include <stdio.h> #define FILENAME "seismic1.txt" #define MAX_SIZE 1000 #define THRESHOLD 1.5 int main(void) { /* Declare variables and function prototypes. */ int k, npts, short_window, long_window; double sensor[MAX_SIZE], time_incr, short_power, long_power, ratio; FILE *file_ptr; double power_w(double * ptr, int n); /* Read sensor data file. */ file_ptr = fopen(FILENAME, "r"); if (file_ptr == NULL) printf("Error opening input file. \n"); else { fscanf(file_ptr, "%d %lf", &npts, &time_incr); if (npts > MAX_SIZE) printf("Data file too large for array. \n"); else { /* Read data into an array. */ for (k = 0; k <= npts - 1; k++) fscanf(file_ptr, "%lf", &sensor[k]); /* Read window sizes from the keyboard. */ printf("Enter num...

Day 16

Image
#include<stdio.h> #include<math.h> #define FILENAME "ENS01.txt" #define MAX_SIZE 1000 int main(void) { int k=0, year[MAX_SIZE], qtr[MAX_SIZE], max_k=0,nor_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(fabs(*(index+nor_k))> fabs(*(index+k))) nor_k=k; k++; } } //print data for max el nion condition printf("Maximun EL Nion Conditions in Dara File \n"); printf("Year: %d, Quarter: %d \n", *(year+max_k),*(qtr+max_k)); printf("EL Nion Conditions closest to normal in Dara File \n"); printf("Year: %d, Quarter: %d \n\n", *(year+nor_k),*(qtr+nor_k)); //Printout all for(int i=0;i<k;i++) printf(...

Day15

//Simple Motor Speed Control Program const int MOTOR=9; const int POT=0; int min_val=0; int max_val=1023; int val=0;//Motor on Digital Pin 9 void setup() {  pinMode (MOTOR, OUTPUT); } void loop() { val=analogRead(POT);    val=map(val,min_val,max_val,0,255);   analogWrite(MOTOR,val); }

Nothing on Day14