Programming Language A
|
|
- Penelope Marsh
- 5 years ago
- Views:
Transcription
1 Programming Language A Takako Nemoto (JAIST) 22 October Takako Nemoto (JAIST) 22 October 1 / 28
2 From Homework 2 Homework 2 1 Write a program calculate something with at least two integer-valued inputs, which is not appeared in this lecture. Add comments to explain what is calculated in the program. 2 Send the program to me via , with the title Homework Lecture2. Please make sure to write your name and student ID number in the mail. Examples etc.. absolute value; area of a triangle; exponentiation; Takako Nemoto (JAIST) 22 October 2 / 28
3 Absolute value int main(void) { int n1, n2; puts("input two integers."); printf("integer 1: "); scanf("%d", &n1); printf("integer 2: "); scanf("%d", &n2); printf("the sum of them is %d.\n", abs(n1 - n2)); Depending on compiler, you may have an error at compiling. This is because the absolute value function abs is not in stdio.h but in stdlib.h. You will not have an error if you add #include <stdlib.h>. Takako Nemoto (JAIST) 22 October 3 / 28
4 Operators and operand Binary operators + plus - minus * multiplication / quotient % reminder Example int x, y; puts("input two integers"); printf("integer x: "); scanf ("%d", &x); printf("integer y: "); scanf ("%d", &y); printf("x + y is %d\n", x + y); printf("x - y = %d\n", x - y); printf("x * y = %d\n", x * y); printf("x / y = %d\n", x / y); printf("x %% y = %d\n", x % y); Input two integers Integer x: 9 Integer y: 8 x + y = 17 x + y = 1 x * y = 72 x / y = 1 x % y = 1 Takako Nemoto (JAIST) 22 October 4 / 28
5 Operators and operand Unary operators unary + operator: + unary operator: - Example int x; printf("input an integer x: "); scanf("%d", &x); printf("+x is %d and -x is %d\n", +x, -x); Input an integer x: 9 +x is 9 and -x is -9 %d can be used several times in one statement. The 1st %d corresponds to the 2nd argument +x and the 2nd %d to the 3rd argument -x. Takako Nemoto (JAIST) 22 October 5 / 28
6 Types Example int main(void) { int n1, n2; printf("input the width: "); scanf("%d",&n1); printf("input the height: "); scanf("%d",&n2); printf("the area of this triangle is %d.\n", n1 * n2 / 2); Input the lwidth: 3 Input the height: 5 The area of this triangle is 7. The last statements calls the integer-value n1 * n2 / 2. Therefore the fraction part is omitted. Takako Nemoto (JAIST) 22 October 6 / 28
7 Types Example int main(void) { double n1, n2; printf("input the width: "); scanf("%lf",&n1); printf("input the height: "); scanf("%lf",&n2); printf("the area of this triangle is %f.\n", n1 * n2 / 2); Input the width: 3 Input the height: 5 The area of this triangle is double is the type for floating point decimal. Note that the conversion specifications are %f in printf and %lf in scanf, both for value with the type double. Takako Nemoto (JAIST) 22 October 7 / 28
8 Type and operators In principle, the output of the operation has the same type as its inputs. If the inputs have different types, then the result has superior type. Example: 5/2 with types int and double 5 int / 2 int = 2 int 5 / 2.0 = 2.5 int double double 5.0 / 2.0 = 2.5 double double double 5.0 / 2 = 2.5 double int double Takako Nemoto (JAIST) 22 October 8 / 28
9 Example of typing int n1, n2, n3, n4; double d1, d2, d3, d4; n1 = 5 / 2; n2 = 5.0 / 2.0; n3 = 5.0 / 2; n4 = 5 / 2.0; d1 = 5 / 2; d2 = 5.0 / 2; d3 = 5.0 / 2; d4 = 5 / 2.0; printf("n1 = %d\n", n1); printf("n2 = %d\n", n2); printf("n3 = %d\n", n3); printf("n4 = %d\n", n4); n1 = 2 n2 = 2 n3 = 2 n4 = 2 d1 = d2 = d3 = d4 = printf("d1 = %f\n", d1); printf("d2 = %f\n", d2); printf("d3 = %f\n", d3); printf("d4 = %f\n", d4); Takako Nemoto (JAIST) 22 October 9 / 28
10 Example of a type error int n, m; double x, y, z, w; printf("input 4 positive integers.\n"); printf("n = "); scanf("%d", &n); printf("m = "); scanf("%d", &m); printf("x = "); scanf("%lf", &x); printf("y = "); scanf("%lf", &y); z = n / m; w = x / y; Input 4 integers. n = 5 m = 2 x = 5 y = 2 n / m is 0 x / y is printf("n / m is %d\n", z); printf("x / y is %f\n", w); Takako Nemoto (JAIST) 22 October 10 / 28
11 As usual arithmetic, * is stronger than +, so we have to write (a+b). %2.1f specifies to print the floating-point-valued (a + b) / 2.0 with at least 2 digits, including 1 fraction part. See p.36 of the textbook. What do we have if we replace 2.0 with 2? Takako Nemoto (JAIST) 22 October 11 / 28 Type and operators int a, b; puts("input two integers."); printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); Input two integers. a = 5 b = 2 The average is 3.5 printf("the average is %2.1f", (a + b) / 2.0);
12 Cast In the previous example, we can declare that (a + b) / 2.0 has the floating-point value as follows: int a, b; puts("input two integers."); printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); printf("the average is %2.1f", (double) (a + b) / 2.0); Takako Nemoto (JAIST) 22 October 12 / 28
13 Exponentiation Some operator has a specific type of output. #include <math.h> double pow(double x, double y); int x, y; printf("input an integer x: "); scanf("%d", &x); printf("input an integer y: "); scanf("%d", &y); printf("exp(x, y) is %lf.", pow(x,y)); /*show the yth power of x*/ Integer x: 5 Integer y: 3 exp(x,y) is 125. Takako Nemoto (JAIST) 22 October 13 / 28
14 If statements int n; printf("input an integer: "); scanf("%d", &no); if (n % 5) puts("your input is not \ndivisible by 5."); Input an integer: 9 Your input is not divisible by 5. Input an integer: 10 The hilighted part means that if the inside of the brackets following if is satisfied, then do the following statements. In this case, puts ("Your input is not \n divisible by 5") is executed if no % 5 is not equal to 0 Takako Nemoto (JAIST) 22 October 14 / 28
15 If-else statements int n; printf("input an integer: "); scanf("%d", &no); if (n % 5) puts("your input is \nnot divisible by 5."); else puts("your input is \ndivisible by 5"); Input an integer: 9 Your input is NOT divisible by 5. Input an integer: 10 Your input is divisible by 5. By else statements, you can execute something if it is not the case of if (...). Takako Nemoto (JAIST) 22 October 15 / 28
16 Multiple if statements int year; printf("input year: "); scanf("%d", &year); if (year % 2) puts("you will have no Olympic game."); else if (year % 4) puts("you will have an winter Olympic game."); else puts("you will have an summer Olympic game."); Input year: 2018 You will have an winter Olympic game. Takako Nemoto (JAIST) 22 October 16 / 28
17 Multiple if statements int year; printf("input year: "); scanf("%d", &year); if (year % 2) puts("you will have no Olympic game."); else if (year % 4) puts("you will have an winter Olympic game."); else puts("you will have an summer Olympic game."); Input year: 2019 You will have no Olympic game. Takako Nemoto (JAIST) 22 October 17 / 28
18 Multiple if statements int year; printf("input year: "); scanf("%d", &year); if (year % 2) puts("you will have no Olympic game."); else if (year % 4) puts("you will have an winter Olympic game."); else puts("you will have an summer Olympic game."); Input year: 2020 You will have an summer Olympic game. Takako Nemoto (JAIST) 22 October 18 / 28
19 Control expression The green part is called control statement: if ( ). Control statements has the int type and if( val )... means that if the value of val is not equal to 0, do the following statements. We can express many conditions with relation and logical operators. Takako Nemoto (JAIST) 22 October 19 / 28
20 Equality & comparison operators Let a and b be floating point (or integer). The following expressions are evaluated as 0 or 1. expression a == b a!= b a > b a < b a >= b a <= b Evaluated 1 if The value of a is equal to the one of b The value of a is not equal to the one of b The value of a is strictly greater than the one of b The value of a is strictly smaller than the one of b The value of a is greater or equal to the one of b The value of a is smaller or equal to the one of b Takako Nemoto (JAIST) 22 October 20 / 28
21 Logical operators Logical operators && and can compound the expressions: Logical operators For control expressions A and B, value of A value of B value of A && B value of A B Takako Nemoto (JAIST) 22 October 21 / 28
22 Example int x, y, z; printf("input 3 integers\n"); printf("x = "); scanf("%d", &x); printf("y = "); scanf("%d", &y); printf("z = "); scanf("%d", &z); if (x == y y == z z == x) printf("at least two of them are equal."); else printf("none of them are equal"); Takako Nemoto (JAIST) 22 October 22 / 28
23 Some more examples Example: Comparison three integers int main (void){ int x, y, z, max; puts("input three integers."); printf("x = "); scanf("%d", &x); printf("y = "); scanf("%d", &y); printf("z = "); scanf("%d", &z); max = x; if (y > max) max = y; if (z > max) max = z; printf ("The maximal value of them is %d.", max); Takako Nemoto (JAIST) 22 October 23 / 28
24 Block You can write multiple statements after if and else using {. int x, y; printf("input an integer x: "); scanf("%d", &x); printf("input an integer y: "); scanf("%d", &y); if (x > y){ printf("the maximum value is %d.\n", x); printf("the minimum value is %d.\n", y); else{ printf("the maximum value is %d.\n", y); printf("the minimum value is %d.\n", x); Takako Nemoto (JAIST) 22 October 24 / 28
25 Case distinction with switch int n; printf("input an integer: "); scanf("%d", &n); switch(n % 3){ case 0 : puts("it is divisible by 3."); break; case 1 : puts("the reminder divided by 3 is 1"); break; case 2 : puts("the reminder divided by 3 is 2"); break; Depending on the value n%3, the statements after case x is executed. break means go out from the switch statement. Takako Nemoto (JAIST) 22 October 25 / 28
26 Switch statement The number after case is label. Labels must be a constant, not a variable. You have to put whitespace between case and the label. If you don t put break;, then the next case x is executed. Try the example List 3-20 in p. 66. Takako Nemoto (JAIST) 22 October 26 / 28
27 Today s exercise and homework Do Exercise 2-4 in the textbook p. 33. Write a program in C s.t. ask 4 integers; print the minimum of them. Rewrite the Olympic-year program with switch. Homework 3 1 Write a program to convert the input Celsius degree temperature into Fahrenheight with 1 floating digit. 2 Write a such program s.t. it asks the elevator A s location (floor); the elevator B s location (floor); the elevator C s location (floor) and your current location (floor), and prints the closest elevator. Hint: Function abs. You should include stdlib.h. 3 See the next page. 4 Read ch.2-4 (pp ) of the textbook. Takako Nemoto (JAIST) 22 October 27 / 28
28 Homework 3 Rewrite the following using switch instead of if: int no; printf("input an integer: "); scanf("%d", &no); if(no % 2) printf("it is odd."); else printf("it is even."); Takako Nemoto (JAIST) 22 October 28 / 28
Programming Language A
Programming Language A Takako Nemoto (JAIST) 30 October Takako Nemoto (JAIST) 30 October 1 / 29 From Homework 3 Homework 3 1 Write a program to convert the input Celsius degree temperature into Fahrenheight
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 17 December Takako Nemoto (JAIST) 17 December 1 / 17 A tip for the last homework 1 Do Exercise 9-5 ( 9-5) in p.249 (in the latest edtion). The type of the second
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 7 January Takako Nemoto (JAIST) 7 January 1 / 13 Usage of pointers #include int sato = 178; int sanaka = 175; int masaki = 179; int *isako, *hiroko;
More informationProgramming Language A
Programming Language A Takako Nemoto (JAIST) 12 November Takako Nemoto (JAIST) 12 November 1 / 25 From Quiz 5 // A program to print the double of the input. int no printf("input an integer: "); scanf("%d",
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 3 December Takako Nemoto (JAIST) 3 December 1 / 18 Today s topics 1 Function-like macro 2 Sorting 3 Enumeration 4 Recursive definition of functions 5 Input/output
More informationProgramming Language A
Programming Language A Takako Nemoto (JAIST) 26 November Takako Nemoto (JAIST) 26 November 1 / 12 Type char char is a datatype for characters. char express integers in certain region. For each ASCII character,
More informationStructured programming. Exercises 3
Exercises 3 Table of Contents 1. Reminder from lectures...................................................... 1 1.1. Relational operators..................................................... 1 1.2. Logical
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 10 December Takako Nemoto (JAIST) 10 December 1 / 15 Strings A string literal is a strings of characters included by double quotations. Examples String literals
More informationWARM UP LESSONS BARE BASICS
WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions
More informationComputer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)
CP Lect 5 slide 1 Monday 2 October 2017 Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont) Cristina Alexandru Monday 2 October 2017 Last Lecture Arithmetic Quadratic equation
More informationArithmetic Expressions in C
Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 28 January Takako Nemoto (JAIST) 28 January 1 / 20 Today s quiz The following are program to print each member of the struct Student type object abe. Fix the
More informationCPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)
CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O) Overview (5) Topics Output: printf Input: scanf Basic format codes More on initializing variables 2000
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 16 January Takako Nemoto (JAIST) 16 January 1 / 15 Strings and pointers #include //11-1.c char str[] = "ABC"; char *ptr = "123"; printf("str = \"%s\"\n",
More informationLecture 6. Statements
Lecture 6 Statements 1 Statements This chapter introduces the various forms of C++ statements for composing programs You will learn about Expressions Composed instructions Decision instructions Loop instructions
More informationC Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }
C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words
More informationC/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 By the end of this lecture, you will be able to identify the
More informationC/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for
C/Java Syntax 1 Lecture 02 Summary Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 2 1 By the end of this lecture, you will be able to identify
More informationEECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution
EECE.2160: ECE Application Programming Spring 2016 Exam 1 Solution 1. (20 points, 5 points per part) Multiple choice For each of the multiple choice questions below, clearly indicate your response by circling
More informationProgramming Language B
Programming Language B Takako Nemoto (JAIST) 21 January Takako Nemoto (JAIST) 21 January 1 / 18 Today s quiz The following is a which returns 0 if s1 and s2 are same, a negative number if s1 is prior to
More informationExpressions and Casting
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationOperators and expressions. (precedence and associability of operators, type conversions).
Programming I Laboratory - lesson 0 Operators and expressions (precedence and associability of operators, type conversions). An expression is any computation which yields a value. When discussing expressions,
More informationDay06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26
Day06 A Young W. Lim 2017-09-20 Wed Young W. Lim Day06 A 2017-09-20 Wed 1 / 26 Outline 1 Based on 2 C Program Control Overview for, while, do... while break and continue Relational and Logical Operators
More informationLecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions
Lecture 02 Summary C/Java Syntax Keywords Variable Declarations Data Types Operators Statements if, switch, while, do-while, for Functions 1 2 By the end of this lecture, you will be able to identify the
More informationWeek 3 More Formatted Input/Output; Arithmetic and Assignment Operators
Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Formatted Input and Output The printf function The scanf function Arithmetic and Assignment Operators Simple Assignment Side Effect
More informationC Program Structures
Review-1 Structure of C program Variable types and Naming Input and output Arithmetic operation 85-132 Introduction to C-Programming 9-1 C Program Structures #include void main (void) { } declaration
More informationCS Spring 2018 Homework #5
CS 1313 010 Spring 2018 Homework #5 Quiz to be held in lecture 9:30-9:45am Mon Feb 19 2018 1. HOW CAN YOU TELL that a declaration statement declares a named constant? 2. HOW CAN YOU TELL that a declaration
More information1. The keyword main in C language is used for
1. The keyword main in C language is used for a. an user defined function *b. the first function to be executed in the program c. an user defined variable 2. The role of a C compiler is to translate a.
More informationCS Fall 2007 Homework #5
CS 1313 010 Fall 2007 Homework #5 Quiz to be held in class 9:30-9:45am Mon Feb 19 2007 1. GIVE TWO EXAMPLES of unary arithmetic operations (NOT operators). 2. For the two examples of unary arithmetic operations,
More informationBasic Assignment and Arithmetic Operators
C Programming 1 Basic Assignment and Arithmetic Operators C Programming 2 Assignment Operator = int count ; count = 10 ; The first line declares the variable count. In the second line an assignment operator
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationInteger Representation. Variables. Real Representation. Integer Overflow/Underflow
Variables Integer Representation Variables are used to store a value. The value a variable holds may change over its lifetime. At any point in time a variable stores one value (except quantum computers!)
More informationEECE.2160: ECE Application Programming Fall 2017
EECE.2160: ECE Application Programming Fall 2017 1. (46 points) C input/output; operators Exam 1 Solution a. (13 points) Show the output of the short program below exactly as it will appear on the screen.
More informationExpressions and Casting. Data Manipulation. Simple Program 11/5/2013
Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence
More informationSummary of Lecture 4. Computer Programming: Skills & Concepts (INF-1-CP1) Variables; scanf; Conditional Execution. Tutorials.
Summary of Lecture 4 Computer Programming: Skills & Concepts (INF-1-CP1) Variables; scanf; Conditional Execution Integer arithmetic in C. Converting pre-decimal money to decimal. The int type and its operators.
More informationC Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationCSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU
CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition
More informationC LANGUAGE A Short Course
C LANGUAGE A Short Course Alvaro F. M. Azevedo http://www.fe.up.pt/~alvaro January 2002 C Language - Alvaro Azevedo 1 ANSI C Standard (ANSI, ISO) Compiled - efficient Low level / high level Other languages
More informationIntroduction to C. Systems Programming Concepts
Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example
More informationQ1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10
EECE.2160: ECE Application Programming Spring 2016 Exam 1 February 19, 2016 Name: Section (circle 1): 201 (8-8:50, P. Li) 202 (12-12:50, M. Geiger) For this exam, you may use only one 8.5 x 11 double-sided
More informationFundamentals of Programming
Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language
More informationSlide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng
Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide
More informationFormatted Input/Output
Chapter 3 Formatted Input/Output 1 The printf Function The printf function must be supplied with a format string ( 格式化字串 ), followed by any values that are to be inserted into the string during printing:
More informationChapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.
Chapter 4: Expressions Chapter 4 Expressions 1 Chapter 4: Expressions Operators Expressions are built from variables, constants, and operators. C has a rich collection of operators, including arithmetic
More informationLecture 3. More About C
Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants
More informationCOP 3223 Introduction to Programming with C - Study Union - Fall 2017
COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................
More informationLectures 4 and 5 (Julian) Computer Programming: Skills & Concepts (INF-1-CP1) double; float; quadratic equations. Practical 1.
Lectures 4 and 5 (Julian) Computer Programming: Skills & Concepts (INF-1-CP1) double; float; quadratic equations 4th October, 2010 Integer arithmetic in C. Converting pre-decimal money to decimal. The
More informationET156 Introduction to C Programming
ET156 Introduction to C Programming g Unit 22 C Language Elements, Input/output functions, ARITHMETIC EXPRESSIONS AND LIBRARY FUNCTIONS Instructor : Stan Kong Email : skong@itt tech.edutech.edu General
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationF28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1
F28HS2 Hardware-Software Interface Lecture 1: Programming in C 1 Introduction in this half of the course we will study: system level programming in C assembly language programming for the ARM processor
More informationLESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long
LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be
More informationExpressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators
Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical
More informationData Type Fall 2014 Jinkyu Jeong
Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants
More informationDay05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14
Day05 A Young W. Lim 2017-10-07 Sat Young W. Lim Day05 A 2017-10-07 Sat 1 / 14 Outline 1 Based on 2 Structured Programming (2) Conditions and Loops Conditional Statements Loop Statements Type Cast Young
More informationC Programs: Simple Statements and Expressions
.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More informationCopyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented
More informationProgramming in C Quick Start! Biostatistics 615 Lecture 4
Programming in C Quick Start! Biostatistics 615 Lecture 4 Last Lecture Analysis of Algorithms Empirical Analysis Mathematical Analysis Big-Oh notation Today Basics of programming in C Syntax of C programs
More informationDisplay Input and Output (I/O)
2000 UW CSE CSE / ENGR 142 Programming I isplay Input and Output (I/O) -1 Writing Useful Programs It s hard to write useful programs using only variables and assignment statements Even our Fahrenheit to
More information2. Numbers In, Numbers Out
COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationIntroduction To Computer Programming Laboratory Source code of a computer program is given below. What do you expect to be displayed?
Introduction To Computer Programming Laboratory 08 16.04.2018 1. Source code of a computer program is given below. What do you expect to be displayed? int a = 1; void fn(void); int a = 2; int a = 3; a++;
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 9 Pointer Department of Computer Engineering 1/46 Outline Defining and using Pointers
More informationCOMP1917 Computing 1 Written Exam Sample Questions
COMP1917 Computing 1 Written Exam Sample Questions Note: these sample questions are intended to provide examples of a certain style of question which did not occur in the tutorial or laboratory exercises,
More informationQuestion 1. Part (a) [2 marks] error: assignment of read-only variable x ( x = 20 tries to modify a constant) Part (b) [1 mark]
Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.
More informationLab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering
2013/2014 Programming Fundamentals for Engineers Lab Lab Session # 1 Introduction to C Language ALQUDS University Department of Computer Engineering Objective: Our objective for today s lab session is
More informationLecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?
Lecture 16 Functions II they re back and they re not happy Daily Puzzle If it is raining at midnight - will we have sunny weather in 72 hours? function prototypes For the sake of logical clarity, the main()
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationMA 511: Computer Programming Lecture 2: Partha Sarathi Mandal
MA 511: Computer Programming Lecture 2: http://www.iitg.ernet.in/psm/indexing_ma511/y10/index.html Partha Sarathi Mandal psm@iitg.ernet.ac.in Dept. of Mathematics, IIT Guwahati Semester 1, 2010-11 Largest
More informationOverview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University
Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the
More informationAN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University
AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:
More informationEngineering program development 6. Edited by Péter Vass
Engineering program development 6 Edited by Péter Vass Variables When we define a variable with its identifier (name) and type in the source code, it will result the reservation of some memory space for
More informationCS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code
CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationCSE 303 Lecture 8. Intro to C programming
CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, 2.2-2.4, 2.6, 3.1, 5.1, 7.1-7.2, 7.5.1-7.5.4, 7.6-7.9, Ch. 8; Programming in C Ch. 1-6 slides created by Marty Stepp http://www.cs.washington.edu/303/
More information1.3b Type Conversion
1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationArithmetic type issues
Arithmetic type issues Type combination and promotion ( a 32) = 97 32 = 65 = A Smaller type (char) is promoted to be the same size as the larger type (int) Determined at compile time - based purely on
More informationComputer Programming: Skills & Concepts (CP) Variables and ints
CP Lect 3 slide 1 25 September 2017 Computer Programming: Skills & Concepts (CP) Variables and ints C. Alexandru 25 September 2017 CP Lect 3 slide 2 25 September 2017 Week 1 Lectures Structure of the CP
More informationQ1: C input/output; operators / 46 Q2: Conditional statements / 34 Q3: While and do-while loops / 20 TOTAL SCORE / 100 Q4: EXTRA CREDIT / 10
EECE.2160: ECE Application Programming Fall 2017 Exam 1 October 4, 2017 Name: Lecture time (circle 1): 8-8:50 (Sec. 201) 12-12:50 (Sec. 203) 1-1:50 (Sec. 202) For this exam, you may use only one 8.5 x
More informationThe Hyderabad Public School, Begumpet, Hyderabad, A.P
The Hyderabad Public School, Begumpet, Hyderabad, A.P. 500 016 2012-13 Department of Computer Science Class 8 Worksheet 3 1) How many times will the following statement execute? ( ) int a=5; while(a>6)
More informationEECE.2160: ECE Application Programming Spring 2018
EECE.2160: ECE Application Programming Spring 2018 1. (46 points) C input/output; operators Exam 1 Solution a. (13 points) Show the output of the short program below exactly as it will appear on the screen.
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 9: Functions I Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture Introduce the switch and goto statements Introduce the arrays in C
More informationThe C Programming Language Part 2. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language Part 2 (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Input/Output Structures and Arrays 2 Basic I/O character-based putchar (c) output getchar
More informationSECTION A TRUE / FALSE QUESTIONS (10 MARKS) (INSTRUCTION: Please answer all 10 questions)
SECTION A TRUE / FALSE QUESTIONS ( MARKS) (INSTRUCTION: Please answer all questions) 1) In pre-test loop, the condition is tested first, before executing the body of the loop. ) The while loop can be used
More informationCourse Outline Introduction to C-Programming
ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,
More informationC Programming
204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library
More informationChapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops.
Chapter 6 Loops 1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly execute some other statement (the loop body). In C, every loop
More informationProcedural Programming
Exercise 6 (SS 2016) 04.07.2015 What will I learn in the 6. exercise Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Home exercise 4 (3 points) Write a program which is able to handle
More information3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.
3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:
More informationMore examples for Control statements
More examples for Control statements C language possesses such decision making capabilities and supports the following statements known as control or decision-making statements. 1. if statement 2. switch
More information2. Numbers In, Numbers Out
REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. REGZ9280 14s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write
More informationStream Model of I/O. Basic I/O in C
Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object
More informationDeclaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.
Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform
More informationSelection Statements. Pseudocode
Selection Statements Pseudocode Natural language mixed with programming code Ex: if the radius is negative the program display a message indicating wrong input; the program compute the area and display
More informationCOP 3275: Chapter 04. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA
COP 3275: Chapter 04 Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA Operators C emphasizes expressions rather than statements. Expressions are built from variables, constants, and
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationBİL200 TUTORIAL-EXERCISES Objective:
Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 20, 2011 6:15 p.m. 8:00 p.m. (105 minutes) Examiners: J. Anderson, T. Fairgrieve,
More information