Thursday

Write a C program to store Kathmandu valley’s 7 days maximum and minimum temperature (in centigrade) and calculate average, maximum, minimum temperature using function and print 7 days temperature, minimum, maximum and average temperature using any high level programming language.

#include<stdio.h>
c programm#include<conio.h>
float maxt(float []);
float min(float []);
float avg(float []);
float m[7],mi[7],a[7];
void main()
{

 float maxtemp, mintemp, avgtemp;
 int i;
 clrscr();
 maxtemp=maxt(m);
 mintemp=min(mi);
 avgtemp=avg(a);
 printf("\n\tMax Temp\t Min Temp \t Average Temp\n");
 for(i=1;i<=7;i++)
 {
 printf("\nDay %d\t%f\t%f\t%f\n",i,m[i],mi[i],a[i]);
 }
 printf("\n Maximum Temperature is %f",maxtemp);
 printf("\n MInimum Temperature is %f",mintemp);
 printf("\n Average Temperature is %f",avgtemp);
 getch();
 }
 float maxt(float m[])
 {
 int i;
 float tm;
 for(i=1;i<=7;i++)
 {
 printf("\nEnter maximum temperature for day %d ", i);
 scanf("%f",&m[i]);
 }

 tm=m[1];
 for(i=2;i<=7;i++)
 {
 if (m[i]>tm)
 tm=m[i];
 }
 return tm;
 }
 float min(float mi[])
 {
  int i;
 float tmi;
 for(i=1;i<=7;i++)
 {
 printf("\nEnter minimum temperature for day %d ", i);
 scanf("%f",&mi[i]);
 }
 tmi=mi[1];
 for(i=2;i<=7;i++)
 {
 if (mi[i]<tmi)
 tmi=mi[i];
 }
 return tmi;


 }
 float avg(float a[])
 {
 int i;
 float ta,s;
 for(i=1;i<=7;i++)
 {
 a[i]=(m[i]+mi[i])/2;
 s=s+a[i];
 }
 ta=s/7;
 return ta;
 }

No comments:

Post a Comment

Rahul-Notes