Lecture Introduction to computer and programming - Lecture No 7

The contents of this chapter include all of the following: C character set, basic constants and variables, output function – printf, input function – scanf, C instructions, integer to float conversion, hierarchy of operator, control instructions. | CSC103: Introduction to Computer and Programming Lecture No 7 Previous lecture C character set Basic constants and variables Output function – printf Input function – scanf C instructions Integer to float conversion Hierarchy of operator Control instructions Today’s Lecture outline Example programs – printf, scanf Decision control structure Relational operator in C if statement if-else statement Nested if else statement Logical operator in C Example program 1 Ahmad’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary and house rent is 20% of basic salary. Write a program to calculate his gross salary and display on screen Inputs: Processing: Output: basic salary calculate dearness allowance, house rent and gross salary display gross salary on screen Example program 2 If a five digit no is input through a key board, write a program to calculate the sum of its digits Inputs: Processing: Output: A five digit no. Separating its all digits, and then calculate sum of these digits Display the sum Decision control structure Selection/Decision Control By default execution of a program is sequential Mostly we want instructions to be executed according to situation. This issue is dealt in C programs using decision controls Selection/Decision Control The if statement The if-else statement Decision depend upon conditions The conditional operators Equality Relational Relational Operators Standard algebraic Relational Operator > = y x = y x <= y x == y x != y Meaning x is greater than y x is less than y x is greater than or equal to y x is less than or equal to y x is equal to y x is not equal to y If Statement if (this condition is true ) execute this statement ; Single-entry/single-exit Nonzero is true, zero is false If Statement Flowchart – 1 Go to program If Statement Flowchart – 2 While purchasing items, a discount of 10% is offered if the quantity is more than . | CSC103: Introduction to Computer and Programming Lecture No 7 Previous lecture C character set Basic constants and variables Output function – printf Input function – scanf C instructions Integer to float conversion Hierarchy of operator Control instructions Today’s Lecture outline Example programs – printf, scanf Decision control structure Relational operator in C if statement if-else statement Nested if else statement Logical operator in C Example program 1 Ahmad’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary and house rent is 20% of basic salary. Write a program to calculate his gross salary and display on screen Inputs: Processing: Output: basic salary calculate dearness allowance, house rent and gross salary display gross salary on screen Example program 2 If a five digit no is input through a key board, write a program to calculate the sum of its digits Inputs: Processing: Output: A five digit no. Separating its all digits, and then .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
Đã 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.