大一新生,全英文教学,因为我们不允许用if语句,所以有些不知道如何做






1
#include <stdio.h>
int main()
{
int age;
printf("Please enter your age: ");
scanf("%d", &age);
age < 18 ? printf("You are not eligible for voting as your age is %d\n", age)
: printf("You are eligible for vote as your age is %d, which is more than or equal to 18\n", age);
return 0;
}
2
#include <stdio.h>
int main()
{
char c;
printf("Please enter a character: ");
scanf("%c", &c);
int lowercase = c >= 'a' ? (c <= 'z' ? 1 : 0) : 0;
int uppercase = c >= 'A' ? (c <= 'Z' ? 1 : 0) : 0;
(lowercase || uppercase) ? printf("%c is an alphabet", c) : printf("%c is not an alphabet", c);
return 0;
}
3
#include <stdio.h>
int main()
{
double temperature;
printf("Please enter a temperature in centigrade: ");
scanf("%lf", &temperature);
printf("Temperature in Fahrenheit is: %.2lf\n", temperature * 9.0 / 5.0 + 32.0);
temperature <= 15.0 ? printf("I am feeling cold\n")
: (temperature <= 25.0 ? printf("I am feeling okay, the temperature is fine\n")
: printf("I am feeling warm!\n"));
return 0;
}