Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre 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; }
Tâche

Swipe to start coding

Construct a calculator that divides numbers, but only if neither of the numbers is zero.

Solution

#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;
}

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 4. Chapitre 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;
}

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt