Lecture_Notes_07_08_09_10

Lecture_Notes_07_08_09_10 - De Morgans Law !(a<b |...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
De Morgan’s Law !(a<b || c<d) is same as !(a<b) && !(c<d) is same as ____________________________ is same as !(a==b) || !(c!=d) is same as a!=b || c==d Note that and and or operators are reversed by moving the not inward.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lazy Evaluation of Logical Operators #include <iostream> #include <cstdlib> using namespace std; int main() { int score=50, labscore=60; if { cout<< "Inside if condition" ; } cout<< "score is " << score<<endl; cout<< "labscore is " <<labscore<<endl; system( "PAUSE" ); return 0; } The && and || operators are computed lazily. As soon as truth value is determined, no further conditions are evaluated
Background image of page 2
1. #include <iostream> 2. using namespace std; 3. int main() 4. { 5. char ch; 6. cout<< "Hello World" <<endl; 7. cout<< "Hello World" <<endl; 8. system ( "PAUSE"); 9. return 0 ; 10. } Why Use Loops?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. #include <iostream> 2. using namespace std; 3. void main() 4. { 5. char ch; 6. for ( int i=0; i<5; i++) 7. { 8. cout<< "Hello World" <<endl; 9. } 10. system ( "PAUSE"); 11. return 0 ; 12. } Why Use Loops?
Background image of page 4
Types of Loops Loops are of three types: while loop - the loop continuation condition is tested at the beginning of the loop before the body of the loop is performed. do/while loop – the loop continuation condition is tested after the loop body is performed; therefore, the loop body will be executed at lease once. for loop – this loop is primarily used for counting
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
while Loop condition statement1; statement2; ……………. while (condition) { statement1; statement2; } system( "PAUSE"); return EXIT_SUCCESS; false true while (condition) statement1; system( "PAUSE"); return EXIT_SUCCESS; Multiple Statements Block of Statements Single Statement
Background image of page 6
while Loop product<10 product= 2*product 1. int main() 2. { 3. int product=0; 4. while (product<10) 5. { 6. product +=2; //equivlent to product=product+2 7. cout<<product<<endl; 8. } 9. system( "PAUSE"); 10. return EXIT_SUCCESS; 11.} false true
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: using while loop 1. #include <iostream> 2. #include <cstdlib> 3. using namespace std; 4. int main() 5. { 6. double green=50, red=45; 7. //cout<<"----------------Green Party in loop---------"<<endl; 8. //for (int i=0; i<10; i++) 9. //{ 10. // green++; 11. // cout<<"Green candidates "<<green<<endl; 12. // } 13. cout<< "----------------------Red Party in Loop-------" <<endl; 14. while (red<55) 15. { 16. red++; 17. cout<< "Red candidates " <<red<<endl; 18. } 19. system( "PAUSE" ); 20. return 0; 21.}
Background image of page 8
(using while loop) #include <iostream> #include <cstdlib> using namespace std; int main() { int xi=0, sum=0, dataSize=0, cntr=0; cout<< "Enter the size of data set" ; cin>> dataSize; while (cntr<dataSize) //loop will repeat itself till { //condition is true cout<< "Enter value" ; cin>>xi; sum=sum+xi; //summation of all input values cntr=cntr+1; //increment cntr } if (dataSize>0) cout<< "Average is" << double
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

Lecture_Notes_07_08_09_10 - De Morgans Law !(a&lt;b |...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online