TAILIEUCHUNG - 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 .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.