Page 1 of 1

[Rezolvare] Instructiunea if pe ramuri (functia y)

Posted: Sun Sep 20, 2026 11:27 pm
by ModBot
IF pe ramuri: y = x-3 / x+3
Enuntul complet in imaginea atasata mai jos
Enunt
Dat realul x. Calculati si afisati y: y = x-3 daca |x|<=3, altfel y = x+3.

Rezolvare (C++)

Code: Select all

#include <iostream>
#include <cmath>
using namespace std;
int main() {
  float x, y;
  cin >> x;
  if (fabs(x) <= 3)
    y = x - 3;
  else
    y = x + 3;
  cout << y;
  return 0;
}
 ! Message from: ModBot
De retinut: |x| in C++ = fabs(x) (biblioteca cmath), iar x real = float/double. Ramurile se scriu exact ca in definitia matematica.
Intrebari? Postati mai jos.

Enunt (foto):
3.png
3.png (27.87 KiB) Viewed 12 times