Plan: 1 For repetition operator


Execution of the if ... else conditional operator


Download 61.79 Kb.
bet3/4
Sana23.09.2023
Hajmi61.79 Kb.
#1686133
1   2   3   4
Bog'liq
Mustaqil ishi

Execution of the if ... else conditional operator

C ++ devices allow you to block operators


allows. Block - Operators between the characters '{' and '}'
sequence, which is considered by the compiler as a single operator.
There may be ad operators within the block, and they are advertised
variables appear (apply) only within this block, outside the block
can't see The block may not be marked with a ‘;’, but inside the block
each expression must end with a ‘;’ sign.
{expression_1; expression_2; ... expression_n;}
As an example, using the discriminant calculation method ax*2+ bx + c = 0
Let's look at the problem of finding the roots of a quadratic equation in the form:
#include
int main() 

float a, b, c; 
float D, x1, x2; 
cout << "ax^2+bx+c=0 tenglama ildizini topish. "; 
cout << "\n a - koeffitsiyentini kiriting: "; 
cin >> a; 
cout << "\n b - koeffitsiyentini kiriting: "; 
cin >> b; 
cout << "\n c - koeffitsiyentini kiriting: "; 
cin >> c; 
D = b * b – 4 * * c; 
if (D < 0) 

cout << "Tenglama haqiqiy ildizga ega emas!"; 
return 0; 

if (D == 0) 

cout << "Tenglama yagona ildizga ega: "; 
x1 = -b / (2 * a); 
cout << "\nx= " << x1; 

else 

cout << "Tenglama ikkita ildizga ega: "; 
x1 = (-b + sqrt(D)) / (2 * a); 
x2 = (-b - sqrt(D)) / (2 * a); 
cout << "\nx1= " << x1; 
cout << "\nx2= " << x2; 

return 0; 

switch operators


Another view of the conditional operator -
switch
network operator
and its syntax is as follows.

switch () 

case

break; 
case
;

Download 61.79 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling