0% found this document useful (0 votes)
1K views

Structuri Alternative: Instructiunea If

The document discusses alternative structures in programming that direct the execution of an instruction sequence (s1 or s2) based on the value of a condition placed in the decision block. These structures are coded using the if instruction. If s1 or s2 contains multiple instructions, they are placed in an instruction block. The if structure may not have an else branch if s2 is empty, making it a pseudo-alternative structure. Syntax examples for if instructions in C/C++ are provided, along with code to solve a linear equation using if/else statements.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Structuri Alternative: Instructiunea If

The document discusses alternative structures in programming that direct the execution of an instruction sequence (s1 or s2) based on the value of a condition placed in the decision block. These structures are coded using the if instruction. If s1 or s2 contains multiple instructions, they are placed in an instruction block. The if structure may not have an else branch if s2 is empty, making it a pseudo-alternative structure. Syntax examples for if instructions in C/C++ are provided, along with code to solve a linear equation using if/else statements.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Structuri alternative

Instructiunea if

http://informaticasite.ro
Structurile alternative dirijeaza executia unei secvente de
instructiuni (s1 sau s2) in functie de valoarea unei conditii
plasate in blocul de decizie. Aceste structuri se codifica
prin instructiunea if. Daca secventa s1 sau s2 contine mai
multe instructiuni, acestea sunt introduse intr-un bloc de
instructiuni. Daca secventa s2 este vida (structura
pseudoalternativa), instructiunea if nu are ramura else.

http://informaticasite.ro
Structura alternativa

altfel atunci
Testare conditie

Secventa 2 (s2) Secventa 1 (s1)

http://informaticasite.ro
Sintaxa instructiunii if

Limbajul C/C++
If (cond_logica)
s1;
else
s2;

http://informaticasite.ro
Exemplu: Rezolvarea ecuatiei de gradul I, de
forma ax+b=0, cu coeficienti reali

Limbajul C/C++
#include<iostream.h>
void main()
{float a,b,x;
cout<<“a=“;cin>>a;cout<<“b=“;cin>>b;
if(a!=0)
{x=-b/a;
cout<<“ec. compatibila determinata x=“<<x;
}
else
if(b!=0)
cout<<“ec. incompatibila”;
else
cout<<“ec. compatibila nedeterminata”;
}

http://informaticasite.ro

You might also like