Miniproject
Miniproject
WEATHER
DATA ANALYZER
STUDENT NAME: ROHAN KUMAR
Introduction
Algorithm
1. Start.
4. Initialize variables:
Sum = 0
Max = very_small_value
Min = very_large_value
Count = 0.
Increment count.
Flowchart
| Start |
|
V
|
V
| Initialize variables |
|
V
| Read temperatures |
|
V
| Calculate average |
| Display results |
| Average, Max, Min |
|
V
|
V
|
V
| Display count |
|
V
| End |
C Code
#include <stdio.h>
#include <stdlib.h>
// Function prototypes
Void analyzeWeatherData(const char *filename, float *average, float
*max, float *min, int *count);
Int countAboveThreshold(float temperatures[], int size, float threshold);
Int main() {
Const char *filename = “weather_data.txt”; // Input file name
Float average = 0, max = 0, min = 0;
Int count = 0;
if (count == 0) {
printf(“No valid data found in the file.\n”);
return 1;
}
// Display results
Printf(“\nResults:\n”);
Printf(“Average Temperature: %.2f\n”, average);
Printf(“Maximum Temperature: %.2f\n”, max);
Printf(“Minimum Temperature: %.2f\n”, min);
// User-defined threshold
Float threshold;
Printf(“\nEnter a temperature threshold: “);
Scanf(“%f”, &threshold);
// Threshold analysis
Float temperatures[count];
Int daysAboveThreshold = countAboveThreshold(temperatures, count,
threshold);
Printf(“Number of days above %.2f: %d\n”, threshold,
daysAboveThreshold);
Return 0;
}
Sum += temp;
If (temp > *max) {
*max = temp;
}
If (temp < *min) {
*min = temp;
}
(*count)++;
}
If (*count > 0) {
Fclose(file);
}
}
Return count;
}
How to Run
25.5
30.0
28.7
22.1
27.3
2. Compile the Program:
./weather_analyzer
Example Output
25.5
30.0
28.7
22.1
27.3
Results:
Average Temperature: 26.72
Conclusion