Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen if-else Operator Practice | Control Statements
C Basics

book
if-else Operator Practice

A Program Alerting High Temperature

c

main

copy
#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

#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?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 4. Kapitel 2
#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

expand
ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

We use cookies to make your experience better!
some-alt