Programming Concepts (Part A) ENGR 10 Introduction to Engineering

Variables A “variable” is a place where we keep a value. A = 10 ; // The value 10 is stored in A. Any statement after the sign “//” is NOT part of the program. It is a comment made by the programmer. WSalary = 800 ; // Any statement can go here. A semicolon is required at the end of each C variable in the program needs to be declared in the beginning of the program. | Programming Concepts (Part A) ENGR 10 Introduction to Engineering What is a program? WHITE CAKE RECIPE Preheat oven to 350 degrees F (175 degrees C). Grease and flour a 9x9 inch pan. In a medium bowl, cream together the sugar and butter. Beat in the eggs. Stir in the vanilla. Combine flour and baking powder, add to the creamed mixture and mix well. Stir in the milk until batter is smooth. Pour or spoon batter into the prepared pan. Bake for 30 to 40 minutes in the preheated oven. A computer program is an ordered list of instructions. It’s like a recipe! In Summary A math example y = [ 3 × ( a × a + 7) ] / b + 4 a2 a2 + 7 3 × (a2 + 7) = 3a2 + 21 (3a2 + 21) / b (3a2 + 21) / b + 4 Sequential Solving following Math conventions for correct answer. Consider the sequential execution of the above expressions to find the value of y: p = a x a; q = p + 7; r = 3 x q; s = r / b; y = s + 4; y = [ 3 × ( a × a + 7) ] / b + 4 An Empty EasyC program C program Flow chart Your program goes here. Your | Programming Concepts (Part A) ENGR 10 Introduction to Engineering What is a program? WHITE CAKE RECIPE Preheat oven to 350 degrees F (175 degrees C). Grease and flour a 9x9 inch pan. In a medium bowl, cream together the sugar and butter. Beat in the eggs. Stir in the vanilla. Combine flour and baking powder, add to the creamed mixture and mix well. Stir in the milk until batter is smooth. Pour or spoon batter into the prepared pan. Bake for 30 to 40 minutes in the preheated oven. A computer program is an ordered list of instructions. It’s like a recipe! In Summary A math example y = [ 3 × ( a × a + 7) ] / b + 4 a2 a2 + 7 3 × (a2 + 7) = 3a2 + 21 (3a2 + 21) / b (3a2 + 21) / b + 4 Sequential Solving following Math conventions for correct answer. Consider the sequential execution of the above expressions to find the value of y: p = a x a; q = p + 7; r = 3 x q; s = r / b; y = s + 4; y = [ 3 × ( a × a + 7) ] / b + 4 An Empty EasyC program C program Flow chart Your program goes here. Your program goes here. C program Logic flow An instruction in C Variables A “variable” is a place where we keep a value. A = 10 ; // The value 10 is stored in A. Any statement after the sign “//” is NOT part of the program. It is a comment made by the programmer. WSalary = 800 ; // Any statement can go here. A semicolon is required at the end of each C instruction. Variables, cont. Every variable in the program needs to be declared in the beginning of the program. int speed ; Declaration of the variable tells the program its name and its type The word “int” indicates that the variable ‘speed’ is an integer variable. Commonly Used Variable Types Variable Type Description Range Int Stores integer values EX: 5, -3200 -32,768 to +32,767 Long Stores integer values with extended range EX: 56, 6000, -4,234,128 -2,147,483,648 to +2,147,483,647 float Stores values with decimal point EX: , [-10^+38, -10^-38] 0 [10^-38, 10^+38] char Stores characters* EX: A, B, @, # _ Global Variable:

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
476    16    1    24-11-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.