In this lesson we will learn about condition instructions:
If (condition1) {instruction 1 ;}
Else if (cond2) {instruction 2;}
.
.
.
Else if (cond n-1) {instruction n-1;}
Else (cond n) {instruction n;}
This function allow us to run instruction 1 if the first condition is true, if not, the computer Will try the second condition and run the instruction2 if it's true, if not, it goes To the next and so on till the n instruction.
Now we'll write an algorithm on how to resolve a 2nd degree equation, Then we'll translate it to a C language.
Before writing this code, I must explain the news:
- The root is (sqrt), for example root(4) =sqrt(4)=2, sqrt is in the header " math.h ", so we must include it.
- We use the bracket, because of this problem :
5+3*4= ? may be 5+3=8 then 8*4=32 or 3*4=12 then 12+5 = 17, In reality it makes 3*4 =12 then 12+5 = 17 because the multiplication has the priority than the addition, so to have the result 32 we must use brackets : (5+3)*4 = 32.- We used (= =) and not (=) because (=) is the affectation, for exampl x=-b/(2*a) mean that we affect the -b/(2*a) value to x so x and this value will be equal, but to test if x and this value are equal we'll write if (x= =-b/(2*a)), its meaning is: if x= this value, the sentence is true, if not it's false but if we write: if (x=-b/(2*a)) then we will affect this value and the sentence will be always true .
| and A , B and (A et B) are three sentences
|
|
Lets A be a sentence proposition, T : true ; F :false
|
||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||