C语言编程问题求助高手!!

来源:百度知道 编辑:UC知道 时间:2024/05/21 20:40:34
麻烦利用“? :” 三目运算符:要求输入以摄氏度表示的温度,输出计算的华氏度的值
#include<stdio.h>
void main()
{
float f,c;
printf("请输入摄氏度:");
scanf("%f",&c);
f=c*9/5+32;
printf("华氏度为:%0.2f",f);

}

我只能这样编出来。公式是:华氏度F=32+(9/5)乘以摄氏度C

麻烦你把完整的程序帮忙编一下好吗?
WXD11011 - 副总裁 十级 我初学者,不好意思看不懂你的。。。

回答者:ElfDN - 魔法师 五级 7-13 18:37 你的三目不能用

其他的我看不懂。。。。。而且也是错的。

好像用不上三目运算吧?

不过,可以用三目运算判断一下输入是否合法。因为摄氏好像有个最低值,-273度吧,好像。

#include <stdio.h>
#include <conio.h>
void main()
{
float w;
char p;
scanf("%f%c",&w,&p);
p=='C'?printf("%f\n",(w-10)*9/5+50):printf("%f\n",(w-50)*5/9+10);
getch();
}

这个程序不适合用? :来写。以上是完成的程序,输入时请在数据后面加一个大写C表示输入的摄氏温度,如果不加或者是加其它字符则表示输入的是华氏温度,如此将会输出对应的摄氏温度。

#include<stdio.h>
main(){
double celsius,fahr;
scanf("%f", &celsius);
fahr=celsius*9/5+32;
printf("%f", fahr);
}
/*好像用不到三目运算符呀,中间也没有判断的过程*/
/*试试看吧*/
#include<stdio.h>
main(){
double celsius,fahr;
scanf("%f", &celsius)? printf("%f", fahr=celsius*9/5+32): ;
}

#include<stdio.h>
void main()
{
float f,c;
int re;
sign1:printf("请输入摄氏度:");
scanf("%f",&c);