Lecture Introduction to computer and programming - Lecture No 9

The contents of this chapter include all of the following: Nested if else statement, logical operator in C, how logical operator can be used to make compound conditions, conditional operator, nested conditional operator, nested if-else, nested conditional operator, loops. | CSC103: Introduction to Computer and Programming Lecture No 9 Previous Lecture Nested if else statement Logical operator in C How logical operator can be used to make compound conditions Conditional operator Today’s lecture outline Nested conditional operator Example programs – nested if-else nested conditional operator Loops while loop Nested conditional operator (expression 1 ? expression 2 : expression 3); Single condition or compound condition (expression 1 ? expression 2 : expression 3); (expression 1 ? expression 2 : expression 3); Example program main( ) { float sal ; printf ("Enter the salary" ) ; scanf ( "%f", &sal ) ; if ( sal 25000 ) printf ( "Manager" ) ; else if ( sal 15000 ) printf ( "Accountant" ) ; else printf ( "Clerk" ) ; } Cont. main( ) { float sal ; printf ("Enter the salary" ) ; scanf ( "%f", &sal ) ; ( (sal 25000) ? printf ( "Manager" ) : (( sal 15000 ) ? printf ( "Accountant") : printf ( "Clerk" ) )); } Example program 1 Three numbers x, y, z are input through the keyboard, write a program to determine the smallest of the three. Write a program Example program 2 Any character is entered through the keyboard, write a program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. Write a program Loops in C Three major loops structures in C while loop for loop do while Loop in general Loop has a termination point finite loop Loop execution stops when the loop condition becomes false Loop has a counter that counts number of iterations of that loop Loop has a statement or a set of statements that are executed until the loop condition become false Formula 1 car race There is a path/track Each car has to complete a certain no of rounds say 10 In each round, when a car cross the finish line the condition is check whether the car has completed total no of round or not. Repetition - Example General form while loop The while . | CSC103: Introduction to Computer and Programming Lecture No 9 Previous Lecture Nested if else statement Logical operator in C How logical operator can be used to make compound conditions Conditional operator Today’s lecture outline Nested conditional operator Example programs – nested if-else nested conditional operator Loops while loop Nested conditional operator (expression 1 ? expression 2 : expression 3); Single condition or compound condition (expression 1 ? expression 2 : expression 3); (expression 1 ? expression 2 : expression 3); Example program main( ) { float sal ; printf ("Enter the salary" ) ; scanf ( "%f", &sal ) ; if ( sal 25000 ) printf ( "Manager" ) ; else if ( sal 15000 ) printf ( "Accountant" ) ; else printf ( "Clerk" ) ; } Cont. main( ) { float sal ; printf ("Enter the salary" ) ; scanf ( "%f", &sal ) ; ( (sal 25000) ? printf ( "Manager" ) : (( sal 15000 ) ? printf ( "Accountant") : printf ( "Clerk"

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
1    73    2    27-04-2024
8    62    2    27-04-2024
3    87    4    27-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.