# 2. Numbers In, Numbers Out

Size: px
Start display at page:

Transcription

1 REGZ9280: Global Education Short Course - Engineering 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2.

2 REGZ s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break each step into smaller steps Convert the basic steps into instructions in the program Use an editor to create a file containing the program Use the compiler to check the syntax of the program Test the program on a range of data

3 REGZ s2 2. Numbers In, Numbers Out 2 Work methodically don t just hack! Like an architect building a house, or a hungry person eating a pizza, you should plan in advance and do the job one piece and one bite at a time, not try to shove the whole thing into your mouth at once. Remember: A day of debugging can save an hour of planning

4 REGZ s2 2. Numbers In, Numbers Out 3 Programming Task Write a program to: read an integer from standard input (keyboard) compute the cube of that integer print that result to standard output (screen)

5 REGZ s2 2. Numbers In, Numbers Out 4 Structure of the Program int main( void ) { // declare variable(s) // read value(s) from standard input (keyboard) // compute the required result // print result to standard output (screen) } return 0;

6 REGZ s2 2. Numbers In, Numbers Out 5 Variables and Types Variables are used to store data In C each variable must have a type C has the following generic data types: char character ( A, e, #,... ) int integer ( 2, 17, -5,... ) double floating point number ( ,... ) there are other types, which are variations on these three.

7 REGZ s2 2. Numbers In, Numbers Out 6 Types Each type is stored in a fixed amount of memory(more in this later). This means that integer types have a limited range and floating point types have a limited range and also precision. You need to keep this in mind when writing your programs. For example on many machines the int data type can hold values between and ( ) Integer overflow errors and floating point precision errors often produce unexpected results wihtout causing the program to crash

8 REGZ s2 2. Numbers In, Numbers Out 7 Variable Declarations Each variable must have a declaration, which tells the compiler to reserve storage space Variable declarations are like the list of ingredients at the top of a cooking recipe A variable declaration must specify a data type and a name double x; char ch; int num; Declarations can be placed after the opening bracket{in a function

9 REGZ s2 2. Numbers In, Numbers Out 8 Function and Variable Names Identifiers Identifier names must be made up of letters and digits. The first character must be a letter. The underscore character _ counts as a letter. uppercase and lowercase are different Restrictions: Keywords like: if, while, do, int, char, double... etc cannot be used as identifiers

10 REGZ s2 2. Numbers In, Numbers Out 9 Input using scanf() #include <stdio.h>... scanf( "%d", &num ); reads input according to a format and stores value(s) in arguments returns the number of input items successfully read, oreof on failure or end of file at least one argument but possibly more each argument (unless an array) must be preceded by ampersand character &

11 REGZ s2 2. Numbers In, Numbers Out 10 scanf() int scanf(const char *format,...); Format can contain: blanks, tabs (whitespace) ignored ordinary characters must match characters of input stream conversion specifications %d decimal integer %ld long integer %lld long long integer %c character %f float %lf double ( long float )

12 REGZ s2 2. Numbers In, Numbers Out 11 Assigning Values to Variables Variables can be assigned values using the=operator n = 23; x = ; Variables can also be initialised when they are declared char c = A ; int x = 75; Variables can be modified during a program cube = num * num * num; x = x + 1; The expression to the right of = is evaluated and the result stored in the variable to the left of the= variables must be assigned before they are used; otherwise they will have garbage values.

13 REGZ s2 2. Numbers In, Numbers Out 12 Arithmetic Operators The following are binary operators: Name Symbol Example Conditions Add + a+b none Subtract a b none Multiply a b none Divide / a / b ignore remainder for integer division Modulus % a % b remainder of a / b

14 REGZ s2 2. Numbers In, Numbers Out 13 Operator Precedence To evaluate the following expression * 3 / 2 % 2 We need to know the precedence of the operators. The result is what we would expect from maths Operators *, /, % have equal and higher precedence than +, -,which also have equal precedence.

15 REGZ s2 2. Numbers In, Numbers Out 14 Abbreviated Assignment Operators C allows certain abbreviated assignment operators when the same variable appears on the left and right side. For example, x += 10; is an abbreviation for x = x + 10; We can also use -= *= /= %=

16 REGZ s2 2. Numbers In, Numbers Out 15 Printing Variable Values with printf() printf("the cube of %d is %d\n", num, cube ); formatted output written to standard output very useful and flexible function can print multiple values in a single statement printf(), used judiciously, can be very helpful for debugging

17 REGZ s2 2. Numbers In, Numbers Out 16 Complete Program #include <stdio.h> int main( void ) { int num, cube; printf("enter a number: " ); // prompt user for input scanf( "%d", &num ); cube = num * num * num; printf("the cube of %d is %d\n", num, cube ); return 0; }

18 REGZ s2 2. Numbers In, Numbers Out 17 Slightly More Elaborate Programming Task Einstein s theory of Relativity predicts that the mass of an object will increase as its velocity increases, according to this equation: where: m m 0 v c is the observed mass is the rest mass is the velocity is the speed of light m= m 0 1 ( v c )2 Write a program which reads the rest mass and velocity from standard input, computes the observed mass and prints it to standard output. (You do not need to understand the physics in order to complete the task!)

19 REGZ s2 2. Numbers In, Numbers Out 18 Variable Names It is helpful to use descriptive names for your variables, which make the code eaiser to read and understand. double mass, rest_mass; double velocity, ratio; These are called variables because their values can vary as the program executes. We might like to treat the speed of light differently, because its value is constant and cannot change during the execution of the program. There are two ways to handle constants in C.

20 REGZ s2 2. Numbers In, Numbers Out 19 Constant Declarations We can declare a constant variable : const double SPEED_OF_LIGHT = ;... or, using scientific notation... const double SPEED_OF_LIGHT = 3e+8; variables declared with theconst qualifier cannot be altered. attempting to alter aconst variable will generate a compilation error.

21 REGZ s2 2. Numbers In, Numbers Out 20 Symbolic Constants Alternatively, we can define a symbolic constant at the top of the file: #define SPEED_OF_LIGHT we use symbolic constants to avoid burying magic numbers or values in the code. symbolic constants make the code easier to understand and maintain #define name replacement text the compiler s pre-processor will parse your code replacing all occurrences of name with replacement text. it will not make the replacement if name is inside quotes or part of another name.

22 REGZ s2 2. Numbers In, Numbers Out 21 Identifiers Conventions many library functions begin their names with an underscore _. For this reason, you should avoid starting your own function or variable names with an underscore. some programmers like to capitalize the first letter of each word SetPrime(); others like to use all lowercase, with an underscore between words int frequency_count; by convention, constants are defined in full uppercase. single letters from a to n often used as counters and indices. longer names are encouraged for external variables and for clarity.

23 REGZ s2 2. Numbers In, Numbers Out 22 scanf() and printf() with doubles printf("enter rest mass: "); scanf( "%lf", &rest_mass ); printf("enter velocity in m/s: "); scanf( "%lf", &velocity );... printf( "Observed mass = %1.6f\n", mass );

24 REGZ s2 2. Numbers In, Numbers Out 23 printf() #include <stdio.h> int printf( const char *format,... ); format may contain ordinary text as well as conversion characters, which print the value of the next argument: %d decimal integer %5d decimal integer at least 5 chars wide %f floating point number %5f floating point number at least 5 chars wide %.3f %5.3f floating point number 3 decimal places floating point number at least 5 chars 3 decimal places

25 REGZ s2 2. Numbers In, Numbers Out 24 Mathematical Equations If necessary, break a large equation into smaller pieces or split it across multiple lines. m= m 0 1 ( v c )2 ratio = velocity / SPEED_OF_LIGHT; mass = rest_mass / sqrt( ratio * ratio );

26 REGZ s2 2. Numbers In, Numbers Out 25 Math Library Functions #include <math.h> sqrt(... ) If your program uses mathematical functions like sqrt(), sin(), cos(), log(), exp(), etc. then you need to include math.h and also compile with the-lm option (which stands for library math ) \$ gcc -Wall -Werror -O -o einstein einstein.c -lm

27 REGZ s2 2. Numbers In, Numbers Out 26 Complete Program #include <stdio.h> #include <math.h> // remember to compile with -lm // speed of light in m/s #define SPEED_OF_LIGHT int main( void ) { double mass, rest_mass; double velocity; double ratio;

28 REGZ s2 2. Numbers In, Numbers Out 27 printf("enter rest mass: "); scanf( "%lf", &rest_mass ); printf("enter velocity in m/s: "); scanf( "%lf", &velocity ); // compute observed mass using Einstein s equation ratio = velocity / SPEED_OF_LIGHT; mass = rest_mass / sqrt( ratio * ratio ); printf( "Observed mass = %1.6f\n", mass ); } return 0;

29 REGZ s2 2. Numbers In, Numbers Out 28 Question What if you type in a velocity that is greater than the SPEED OF LIGHT? What will happen?

### 2. 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

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### Integer 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!)

### ANSI 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

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

### Programming 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()

### Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

### c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

### sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

INPUT AND OUTPUT IN C Function: printf() library: sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ; format_string it is

### A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

### Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

### ET156 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

### Basic Types and Formatted I/O

Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

### 2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

### printf( Please enter another number: ); scanf( %d, &num2);

CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

### C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

### Chapter 1 & 2 Introduction to C Language

1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

### CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Fundamentals of Programming

Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

### C 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,

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

### C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

### CS16 Exam #1 7/17/ Minutes 100 Points total

CS16 Exam #1 7/17/2012 75 Minutes 100 Points total Name: 1. (10 pts) Write the definition of a C function that takes two integers `a` and `b` as input parameters. The function returns an integer holding

### ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1 Data Types

### Full file at

Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

### Overview 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

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

### Data types, variables, constants

Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

### Fundamental 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

### 12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

### Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

### Number Systems, Scalar Types, and Input and Output

Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### Basics of Programming

Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

### Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

### Data Types and Variables in C language

Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

### Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

### The C++ Language. Arizona State University 1

The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

### Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

### 9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

### Arithmetic 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

### LESSON 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

### The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

### Should you know scanf and printf?

C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

### C 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

### Creating a C++ Program

Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

### BIL 104E Introduction to Scientific and Engineering Computing. Lecture 1

BIL 104E Introduction to Scientific and Engineering Computing Lecture 1 Introduction As engineers and scientists why do we need computers? We use computers to solve a variety of problems ranging from evaluation

### Chapter 2. Outline. Simple C++ Programs

Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### INTRODUCTION 1 AND REVIEW

INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

### 6.096 Introduction to C++ January (IAP) 2009

MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

### Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the

### Compiling and Running a C Program in Unix

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name

### C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

### UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

### Expressions. 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

### Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

### Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

Examples of Software Programming and Data Structure Lecture 2 Sudeshna Sarkar Read an integer and determine if it is a prime number. A Palindrome recognizer Read in airline route information as a matrix

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

### IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

### Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

### Fundamentals of C. Structure of a C Program

Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments - Different Modes 2 Comments - Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file

### CPE 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

### C introduction: part 1

What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

### AN 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:

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### LECTURE 02 INTRODUCTION TO C++

PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

### COMP s1 Lecture 1

COMP1511 18s1 Lecture 1 1 Numbers In, Numbers Out Andrew Bennett more printf variables scanf 2 Before we begin introduce yourself to the person sitting next to you why did

### Computer Programming

Computer Programming Introduction Marius Minea marius@cs.upt.ro http://cs.upt.ro/ marius/curs/cp/ 26 September 2017 Course goals Learn programming fundamentals no prior knowledge needed for those who know,

### Basic 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

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. A Simple Program. simple.c: Basics of C /* CPE 101 Fall 2008 */ /* Alex Dekhtyar */ /* A simple program */ /* This is a comment!

### PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite

### Structured programming

Exercises 2 Version 1.0, 22 September, 2016 Table of Contents 1. Simple C program structure................................................... 1 2. C Functions..................................................................

### BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

### CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world

### Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

### Stream 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

### Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify

### 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Gaddis: Starting Out with Python, 2e - Test Bank Chapter Two MULTIPLE CHOICE 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical

### C Tutorial: Part 1. Dr. Charalampos C. Tsimenidis. Newcastle University School of Electrical and Electronic Engineering.

C Tutorial: Part 1 Dr. Charalampos C. Tsimenidis Newcastle University School of Electrical and Electronic Engineering September 2013 Why C? Small (32 keywords) Stable Existing code base Fast Low-level

### Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

### Work relative to other classes

Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

### 2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

### Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required