當前位置:首頁 » 編程語言 » 計算平均溫度的c語言程序
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

計算平均溫度的c語言程序

發布時間: 2022-05-26 04:34:09

『壹』 c語言,跪求大神幫幫忙:輸入一個月中的最低溫度,輸出高於等於小於平均溫度的天數

printf("%df\n",num3);
多寫了一個字母f

『貳』 c語言,編寫一個程序處理一組日最高氣溫.程序需要統計並列印出高溫天數(最高溫度為華氏85或更高)

你好!

##include<stdio.h>

main()
{
inta[]={55,62,68,74,59,45,41,58,60,67,65,78,82,88,91,92,90,93,87,80,78,79,72,68,61,59};
inti=0;
intgao=0;
intdi=0;
intshu=0;
intsum=0;
for(i=0;i<26;i++)
{
if(a[i]<=85&&a[i]>=60)
shu++;
if(a[i]>85)
gao++;
if(a[i]<60)
di++;
sum=sum+a[i];
}
printf("高溫天數:%d 舒適天數:%d 低溫天數:%d 平均氣溫:%lf ",gao,shu,di,(double)sum/26);
}

『叄』 C語言!!!!

第8題說的很清楚啊,每一行就是一天,每一列就是每天的小時數,也就是這個二維數組類似於這樣

0點1點2點3點4點....
1號889910
2號6571011
。。。

算每一天的平均氣溫,就把每一行的數據加起(比如1號就累加第一行的,除以24,就得到1號的平均氣溫)。

同樣,算0點的平均氣溫,就把第一列的數據加起來,除以30,就是本月0點的平均溫度。

『肆』 C語言編程:輸入一個華氏溫度,要求輸出攝氏溫度,公式為:c=5(F-32)/9,謝謝!

可以參考下面的代碼:

#include <stdio.h>

int main(void)

{

float c,f;

printf("請輸入一個華氏溫度: ");

scanf("%f",&f);

c=(f-32)*5/9;

printf("對應的攝氏溫度是:%.2f ",c);

}

(4)計算平均溫度的c語言程序擴展閱讀:

printf()函數是格式化輸出函數, 一般用於向標准輸出設備按規定格式輸出信息。在編寫程序時經常會用到此函數。函數的原型為:int printf(const char *format, ...);函數返回值為整型,若成功則返回輸出的字元數,輸出出錯則返回負值。

scanf函數原型:intscanf(constchar*restrictformat,...);

返回值

scanf函數返回成功讀入的數據項數,讀入數據時遇到了「文件結束」則返回EOF。

『伍』 c語言題目。。。

#include<stdio.h>
voidmain()
{
FILE*fp;
intc;
intvalue;
intsum,count,count1,count2,count3;
fp=fopen("records.txt","rb");
if(fp!=0)
{
sum=count=count1=count2=count3=0;
c=fgetc(fp);
while(1)
{
if(c>='0'&&c<='9')
{
value=0;
do
{
value=value*10+(c-'0');
c=fgetc(fp);
}while(c>='0'&&c<='9');
sum+=value;
count++;
if(value>=85)
count1++;
elseif(value>=60)
count2++;
else
count3++;
}
if(c==EOF)
break;
do
{
c=fgetc(fp);
}
while((c<'0'||c>'9')&&c!=EOF);
}
printf("高溫天數:%d 舒適天數:%d 寒冷天數:%d 平均溫度:%0.1f ",count1,count2,count3,(float)sum/count);
fclose(fp);
}
}

『陸』 【求助】有多年逐日氣溫,求多年逐月平均溫度,用C語言怎麼編程序

這個這個還真的很難,不會。

『柒』 編程白痴求個C語言演算法。現有一年中每一天的溫度,怎麼把這一連串數據賦值給日期。

#include <iostream>
#include <vector>
using namespace std;

external double _temp[366]; //儲存溫度的數組
vector<double> temp_xun;

double get_date(int year, int month, int day)//根據年月日決定這一天是當年第幾天
{
// Determine the day in year
int N_day=365;
if(year%400==0(year%100!=0&&year%4==0))N_day=366;

const int dayinmonth[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int date = 0;
for(i=0;i<month;i++)
{
if(i!=month-1){data+=dayinmonth[i];}
else data+=day
}
if(N_day==365&&month==2&&day==29)
{cout<<"Error: Only 28 days in February"<<end; return -1}
else{return date};
}

double get_temp(int year, int month, int date)//得到某一天的溫度
{
int day = get_date(year, month, date);//這一年的第幾天?
if(day!=-1)
return _temp[day];
else
{
cout<< "No temperature information for Feb 29, "<<year<<endl;
return -1000;
}
}

double get_temp_10day_average(int day, int month, int xun )//一旬的平均溫度,1-10算上旬,11-20中旬,20-31下旬
{
if(xun>3)
{ cout<<"Error, a month only have 3 10days at most!"<<end;return -10000;
}
int date_begin, date_end;
int day_begin,day_end;
if(1==xun){day_begin=1;day_end=10;}
if(2==xun){day_begin=11;day_end=20};
if(3==xun){day_begin=21;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
day_end=31;
else if(month!=2) day_end=30;
else{
if(year%400==0||(year%4==0&&year%100!=0))day_end=29;
else day_end=28;
}
}
date_begin=get_date(year,month,day_begin);
date_end=get_date(year,month,day_end);
double temp_sum=0; //sum of temperature
for(int i=date_begin;i<date_end;i++)
{
temp_sum+=_temp[i];
}
double temp_ave=temp_sum/((double)(date_end)-(double)(date_begin));
return temp_ave;
}

int get_temp_10day(int year,int month, int xun)
{
if(xun>3)
{ cout<<"Error, a month only have 3 10days at most!"<<end;return -10000;
}
int date_begin, date_end;
int day_begin,day_end;
if(1==xun){day_begin=1;day_end=10;}
if(2==xun){day_begin=11;day_end=20};
if(3==xun){day_begin=21;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
day_end=31;
else if(month!=2) day_end=30;
else{
if(year%400==0||(year%4==0&&year%100!=0))day_end=29;
else day_end=28;
}
}
date_begin=get_date(year,month,day_begin);
date_end=get_date(year,month,day_end);
temp_xun.resize(0);

for(int i=date_begin;i<date_end;i++)
{
temp_xun.push_back(_temp[i]);
}
return 0;
}

『捌』 C語言 輸入一個月及每日氣溫(含有1位小數),程序輸出該月平均,最高和最底氣溫

#include<stdio.h>

int main()

{

int days;
float sum,max,min,temp;

max=sum=0.0;
min=100.0;
printf("請輸入當月的天數:");
scanf("%d",&days);
for(int i=0;i<days;i++)

{

printf("請輸入%d日的氣溫:",i+1);

scanf("%f",&temp);

sum+=temp;

max=max<temp?temp:max;

min=min>temp?temp:min;

}

printf("當月最高氣溫:%.1f\n",max);

printf("當月最低氣溫:%.1f\n",min);

printf("當月平均氣溫:%.1f\n",sum/days);

return 0;

}

『玖』 [C語言]一個溫度數據表五行四列,求行平均和列平均值

int main()
{
int a[5][4] = {{1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4}, {5, 5, 5, 5}};
for (int i = 0; i < 5; ++i)
{
int sum = 0, avg = 0;
for (int j = 0; j < 4; ++j)
{
sum = sum + a[i][j];
}
printf("row %d %.2f\n", i + 1, float(sum / 4));
}
for (int j = 0; j < 4; ++j)
{
int sum = 0, avg = 0;
for (int i = 0; i < 5; ++i)
{
sum = sum + a[i][j];
}
printf("col %d %.2f\n", j + 1, float(sum / 5));
}
}

『拾』 c語言程序設計 溫度轉換

#include<stdio.h>
intmain()
{intd;
floatt,t1;
printf("確定要轉換的類型: 1)華氏轉攝氏 ");
printf("2)攝氏轉華氏 請選擇1或2:");
scanf("%d",&d);
printf("請輸入溫度:");
scanf("%f",&t);
if(d==1)
{t1=(t-32)*5/9;
printf("攝氏溫度為%.2f度 ",t1);
}
else
{t1=t*9/5+32;
printf("華氏溫度為%.2f度 ",t1);
}
return0;
}