C语言程序设计题 麻烦大家做一下

2025-01-18 20:10:57
推荐回答(2个)
回答1:

第一题我不写了,纯功夫活儿,声明一个整型变量month,用scanf函数读入。写一个12分支+1个default的switch语句,12个分支以month为参考,分别为case1到case12,每个分支打印该月的英语单词。default打印错误信息。

第二题:

#include
#define LEN 100
#define WEI 25
#define SPOW 0.5
#define LPOW 1.2

double get_short_price( double wei )
{
if( wei<=WEI )
return wei*SPOW;
else
return WEI*SPOW+(wei-WEI);
}

int main()
{
double length, weight, price;

printf("Input the length(km) and the weight(kg):\n");
scanf("%lf %lf", &length, &weight);

while (length<=0||weight<=0)
{
printf("Are you kidding me? Input again!\n");
scanf("%lf %lf", &length, &weight);
}

if(length<100)
price = get_short_price( weight );
else
price = LPOW*get_short_price( weight );

printf("You should pay $%.2lf.\n", price);
}

回答2:

第一道:
#include
void main()
{
int i;
cout<<"input the number:";
cin>>i;
switch(i)
{
case 1:cout<<"January";break;
case 2:cout<<"February";break;
case 3:cout<<"March";break;
case 4:cout<<"April";break;
case 5:cout<<"May";break;
case 6:cout<<"June";break;
case 7:cout<<"July";break;
case 8:cout<<"August";break;
case 9:cout<<"September";break;
case 10:cout<<"Octobor";break;
case 11:cout<<"November";break;
case 12:cout<<"December";break;
default:cout<<"error!";
}
}