if-else Operator Practice
A Program Alerting High Temperature
main
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
int main()
{
int temperature = 200; // in celsius
if (temperature > 80)
{
printf("Temperature is so high: %d degrees Celsius\n", temperature);
}
else
{
printf("Temperature is normal: %d degrees Celsius\n", temperature);
}
return 0;
}
123456789101112131415161718#include <stdio.h> int main() { int temperature = 200; // in celsius if (temperature > 80) { printf("Temperature is so high: %d degrees Celsius\n", temperature); } else { printf("Temperature is normal: %d degrees Celsius\n", temperature); } return 0; }
Aufgabe
Swipe to start coding
Construct a calculator that divides numbers, but only if neither of the numbers is zero.
Lösung
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
int main()
{
int a = 2;
double b = 3;
if (a != 0 && b != 0)
printf(" Answer: %f \n", a / b);
else if (a == 0 && b != 0)
printf(" Answer: 0 / b = an infinitesimal number\n");
else if (a != 0 && b == 0)
printf("Answer: a / 0 = an infinite number\n");
else
printf("Answer: 0 / 0 = ???");
return 0;
}
War alles klar?
Danke für Ihr Feedback!
Abschnitt 4. Kapitel 2
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
int main()
{
int a = 2;
double b = 3;
if (___)
printf(" Answer: %f \n", a / b);
else if (___)
printf(" Answer: 0 / b = an infinitesimal number\n");
else if (___)
printf("Answer: a / 0 = an infinite number\n"); // division by zero
else
printf("Answer: 0 / 0 = ???"); // division by zero
return 0;
}
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen