Decision making and control structure quiz

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
Advertisements

Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Fundamental of C programming
Chapter 3A Review boolean fun = true; if(fun) System.out.print(“yeah!”);
What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
Computer Science 2212a/b - UWO1 Structural Testing Motivation The gcov Tool An example using gcov How does gcov do it gcov subtleties Further structural.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
1. 2 Revision To understand the term Nesting –To be able to write programs that contain nested loops. –To be able to dry run programs containing nested.
Control Flow C and Data Structures Baojian Hua
Conditional Statements If these were easy then everyone would them!
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
1 Selection in C. 2 If / else if statement:  The else part of an if statement can be another if statement. if (condition) … else if (condition) … else.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Selection in C.
Flow of Control Java Programming Mrs. C. Furman January 5, 2009.
Lec 6 Logical Operators String comparison. Review – if statement syntax OR.
RELATIONAL OPERATORS LOGICAL OPERATORS CONDITION Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Making Decisions (True or False) Relational Operators >greater than =greater than or equal to
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Introduction to Computing Lecture 05: Selection (continued) Introduction to Computing Lecture 05: Selection (continued) Assist.Prof.Dr. Nükhet ÖZBEK Ege.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Lecture 7: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Glenn Stevenson CSIS 113A MSJC CSIS 113A Lecture 2.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
CONTROL STRUCTURE. 2 CHAPTER OBJECTIVES  Learn about control structures.  Examine relational and logical operators.  Explore how to form and evaluate.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
PHY 107 – Programming For Science. Announcements no magic formulas exist  Need to learn concepts: no magic formulas exist  Single solution not useful;
Review (before the 1 st test): while (conditions) { statements; } while loop: if/else if/else statements: if (conditions) { statements; } else if (different.
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Making Decisions in c. 1.if statement Imagine that you could translate a statement such as “If it is not raining, then I will go swimming” into the C.
THE DECISIONS CONTROL STRUCTURE! CHAPTER 2. Transfer of control statement: o The statement of computer program are executed one after the other in the.
Decision making If.. else statement.
UMBC CMSC 104 – Section 01, Fall 2016
Java for Beginners University Greenwich Computing At School DASCO
Decisions Chapter 4.
CMPT 201 if-else statement
Chapter 4 (Conditional Statements)
Printing Lines of Asterisks
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Rule Exercises Status of the Ball Definitions and Rule 15
Rule Exercises Status of the Ball Definitions and Rule 15
Rule Exercises – Rule 20 Correct Answer – False (Rule 20-2a)
Introduction To Programming Information Technology , 1’st Semester
Lecture 2: Logical Problems with Choices
Relational and Logical Operators
Chapter 5 Decision Making and Branching
Decision making If statement.
Visual Basic – Decision Statements
Relational and Logical Operators
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Computer Programming Basics
Relational and Logical Operators
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Relational and Logical Operators
IPC144 Introduction to Programming Using C Week 2 – Lesson 2
Agenda Warmup Review Finish 1.2 Assignments Lesson 1.3 (If Statements)
Presentation transcript:

Decision making and control structure quiz

What would be the output of the following program 1 main( ) { int i = 4, z = 12 ; if ( i = 5 || z > 50 ) printf ( "\nDean of students affairs" ) ; else printf ( "\nDosa" ) ; }

What would be the output of the following program 2 main( ) { int i = 4, z = 12 ; if ( i = 5 && z > 5 ) printf ( "\nLet us C" ) ; else printf ( "\nWish C was free !" ) ; }

What would be the output of the following program 3 main( ) { int i = 4, j = -1, k = 0, w, x, y, z ; w = i || j || k ; x = i && j && k ; y = i || j && k ; z = i && j || k ; printf ( "\nw = %d x = %d y = %d z = %d", w, x, y, z ) ; }

What would be the output of the following program 4 main( ) { int i = 4, j = -1, k = 0, y, z ; y = i + 5 && j + 1 || k + 2 ; z = i + 5 || j + 1 && k + 2 ; printf ( "\ny = %d z = %d", y, z ) ; }

What would be the output of the following program 5 main( ) { int i = -3, j = 3 ; if ( !i + !j * 1 ) printf ( "\nMassaro" ) ; else printf ( "\nBennarivo" ) ; }

What would be the output of the following program 6 main( ) { int a = 40 ; if ( a > 40 && a < 45 ) printf ( "a is greater than 40 and less than 45" ) ; else printf ( "%d", a ) ; }

What would be the output of the following program 7 main( ) { int p = 8, q = 20 ; if ( p == 5 && q > 5 ) printf ( "\nWhy not C" ) ; else printf ( "\nDefinitely C !" ) ; }

What would be the output of the following program 8 main( ) { int i = -1, j = 1, k ,l ; k = i && j ; l = i || j ; printf ( "%d %d", I, j ) ; }

What would be the output of the following program 9 main( ) { int x = 20 , y = 40 , z = 45 ; if ( x > y && x > z ) printf( "x is big" ) ; else if ( y > x && y > z ) printf( "y is big" ) ; else if ( z > x && z > y ) printf( "z is big" ) ; }

What would be the output of the following program 10 main( ) { int i = -1, j = 1, k ,l ; k = !i && j ; l = !i || j ; printf ( "%d %d", i, j ) ; }

What would be the output of the following program 11 main( ) { int j = 4, k ; k = !5 && j ; printf ( "\nk = %d", k ) ; }

Point out the error if any 12 main( ) { int i = 2, j = 5 ; if ( i == 2 && j == 5 ) printf ( "\nSatisfied at last" ) ; }

Point out the error if any 13 main( ) { int code, flag ; if ( code == 1 & flag == 0 ) printf ( "\nThe eagle has landed" ) ; }

Point out the error if any 14 main( ) { char spy = 'a', password = 'z' ; if ( spy == 'a' or password == 'z' ) printf ( "\nAll the birds are safe in the nest" ) ; }

Point out the error if any 15 main() { int i = 10, j = 20 ; if ( i = 5 ) && if ( j = 10 ) printf ( "\nHave a nice day" ) ; }

Point out the error if any 16 main( ) { int x = 10 , y = 20; if ( x >= 2 and y <=50 ) printf ( "\n%d", x ) ; }

Point out the error if any 17 main( ) { int a, b ; if ( a == 1 & b == 0 ) printf ( "\nGod is Great" ) ; }

Point out the error if any 18 main( ) { int x = 2; if ( x == 2 && x != 0 ) ; printf ( "\nHi" ) ; printf( "\nHello" ) ; } else printf( "Bye" ) ;

Point out the error if any 19 main( ) { int i = 10, j = 10 ; if ( i && j == 10) printf ( "\nHave a nice day" ) ; }

What would be the output of the following program 20 main( ) { int i = -4, j, num ; j = ( num < 0 ? 0 : num * num ) ; printf ( "\n%d", j ) ; }

What would be the output of the following program 21 main( ) { int k, num = 30 ; k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ; printf ( "\n%d", num ) ; }

What would be the output of the following program 22 main( ) { int j = 4 ; ( !j != 1 ? printf ( "\nWelcome") : printf ( "\nGood Bye") ) ; }

Point out the error if any 23 main( ) { int tag = 0, code = 1 ; if ( tag == 0 ) ( code > 1 ? printf ( "\nHello" ) ? printf ( "\nHi" ) ) ; else printf ( "\nHello Hi !!" ) ; }

Point out the error if any 24 main( ) { int ji = 65 ; printf ( "\nji >= 65 ? %d : %c", ji ) ; }

Point out the error if any 25 main( ) { int i = 10, j ; i >= 5 ? ( j = 10 ) : ( j = 15 ) ; printf ( "\n%d %d", i, j ) ; }

Point out the error if any 26 main( ) { int a = 5 , b = 6 ; ( a == b ? printf( "%d",a) ) ; }

Point out the error if any 27 main( ) { int n = 9 ; ( n == 9 ? printf( "You are correct" ) ; : printf( "You are wrong" ) ;) ; }

Point out the error if any 28 main( ) { int kk = 65 ,ll ; ll = ( kk == 65 : printf ( "\n kk is equal to 65" ) : printf ( "\n kk is not equal to 65" ) ) ; printf( "%d", ll ) ; }

Point out the error if any 29 main( ) { int x = 10, y = 20 ; x == 20 && y != 10 ? printf( "True" ) : printf( "False" ) ; }