Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, September 3, 2022

C program to read 7 days maximum and minimum temperature (in centigrade) and calculate average, maximum and minimum temperature using array.

C program to read 7 days maximum and minimum temperature (in centigrade) and calculate average, maximum and minimum temperature using array.





Introduction:

Programming is all about solving problems, and arrays are a powerful tool that programmers use to solve problems efficiently. In this article, we will explore a 'C' program that reads the maximum and minimum temperature for seven days (in centigrade) and calculates the average, maximum, and minimum temperature using arrays. This program is an excellent example of how arrays can be used to efficiently store and manipulate data.

The Program:

The first step in writing this program is to declare an array to store the temperature data. We will use a one-dimensional array to store the maximum and minimum temperatures for each day. The size of the array will be seven, as we are collecting data for seven days.

 #include<stdio.h>

#include<conio.h>

main()

{

float mtemp[7], mitemp[7], max, min, avg;

int i;

float sum=0;

printf("Enter minimum and maximum temperature of 7 days\n");

for(i=0;i<7;i++)

{

printf("enter maximum temperature\n");

scanf("%f",&mtemp[i]);

printf("Enter minimum temperature\n");

scanf("%f",&mitemp[i]);

}

max=mtemp[0];

min=mitemp[0];

for(i=1;i<7;i++)

{

if(mtemp[i]>max)

max=mtemp[i];

if(mitemp[i]<min)

min=mitemp[i];

sum=sum+(mtemp[i]+mitemp[i]);

}

printf("\n Maximum temperature=%f",max);

printf("\n Minimum temperature=%f",min);

avg=sum/14;

printf("\n Average temperature=%f",avg);

getch();

}


Output:




Conclusion:

In conclusion, this 'C' program is a great example of how arrays can be used to efficiently store and manipulate data. By using an array to store the temperature data, we can easily calculate the average, maximum, and minimum temperatures for seven days. This program can be used as a starting point for more complex data analysis tasks, and it is an excellent example of how arrays can be used in real-world applications. As a programmer, it is essential to understand how to use arrays efficiently, as they are a fundamental tool in data manipulation and analysis.


You can also Read:






No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages