Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Switch Calculator | Conditional Control Flow Practice
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C Conditional Statements

bookChallenge: Switch Calculator

Tâche

Swipe to start coding

Write a function that takes two integers and a character representing an operator (+, -, *, or /). Use a switch statement to perform the corresponding arithmetic operation:

  • If the operator is +, print the sum of the two numbers;
  • If the operator is -, print the difference of the two numbers;
  • If the operator is *, print the product of the two numbers;
  • If the operator is /, print the quotient of the two numbers;
  • If the operator is not one of the above, or if division by zero is attempted, return zero and print zero.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 2
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

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

close

bookChallenge: Switch Calculator

Glissez pour afficher le menu

Tâche

Swipe to start coding

Write a function that takes two integers and a character representing an operator (+, -, *, or /). Use a switch statement to perform the corresponding arithmetic operation:

  • If the operator is +, print the sum of the two numbers;
  • If the operator is -, print the difference of the two numbers;
  • If the operator is *, print the product of the two numbers;
  • If the operator is /, print the quotient of the two numbers;
  • If the operator is not one of the above, or if division by zero is attempted, return zero and print zero.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 2
single

single

some-alt