编写一个程序来操纵温度细节,如下所示.
- 输入要计算的天数.- 主要功能
- 以摄氏度输入温度 - 输入功能
- 将温度从摄氏度转换为
华氏度. - 单独功能- 查找华氏温度的平均温度.
如何在没有初始数组的情况下制作这个程序?
#include<stdio.h>
#include<conio.h>
void input(int);
int temp[10];
int d;
void main()
{
int x=0;
float avg=0,t=0;
printf("\nHow many days : ");
scanf("%d",&d);
input(d);
conv();
for(x=0;x<d;x++)
{
t=t+temp[x];
}
avg=t/d;
printf("Avarage is %f",avg);
getch();
}
void input(int d)
{
int x=0;
for(x=0;x<d;x++)
{
printf("Input temperature in Celsius for #%d day",x+1);
scanf("%d",&temp[x]);
}
}
void conv()
{
int x=0;
for(x=0;x<d;x++)
{
temp[x]=1.8*temp[x]+32;
}
}
Run Code Online (Sandbox Code Playgroud)