CGS 3460 Servers n rain.cise.ufl.edu n sand.cise.ufl.edu n shine.cise.ufl.edu n thunder.cise.ufl.edu n storm.cise.ufl.edu.

Slides:



Advertisements
Similar presentations
Arithmetic Calculations
Advertisements

Computer Programming w/ Eng. Applications
We Have Learned main() { … } Variable –Definition –Calculation –Display We can do some real programming! –Think about your solution design –Express design.
Types and Arithmetic Operators
Outline 2.1 Introduction 2.2 Basics of C Programs
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 1: Types, Operators and Expressions.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
Friday, December 08, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
Lab 5 rC language Elements rVariables Declarations and Data Types rGeneral Form of a C Program rArithmetic Expressions rFormatting Numbers rExercises Note:
Introduction to C Systems Programming. Systems Programming: Introduction to C 2 Systems Programming: 2 Introduction to C  A ‘C’ Program –Variable Declarations.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
CIS 234: Order of Operations, Shortcut & Other Operators Dr. Ralph D. Westfall February, 2004.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Chapter 11-12, Appendix D C Programs Higher Level languages Compilers C programming Converting C to Machine Code C Compiler for LC-3.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall by Deepak Majeti M-Tech CSE
***** SWTJC STEM ***** Chapter 2-3 cg 29 Java Operators Recall Java’s programming components: Packages - Collection of classes (Programs) Classes - Collections.
CHAPTER:8 OPERATORS AND EXPRESSION IN C++ Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Chapter 2 part #4 Operator
Object-Oriented Programming Using C++ Third Edition Chapter 2 Evaluating C++ Expressions.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
Chapter 2: Using Data.
C/C++ Operators Binary Operators: Operators Between Two Operands: Operator + MeaningExample Definition. Additionx = 6 + 2;Add the values on either side.
CGS 3460 Unix Commands n man – manual (man gcc) n ls – list directory contents (ls) n pwd – prints working directory (pwd) n cd – change directory (cd.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 3: Introduction to C: Input & Output, Assignments, Math functions.
CGS 3460 Input and Output Revisited. CGS 3460 Display Integer Variables – I #include Preprocessor: interact with input/output of your computer Start point.
COMP Primitive and Class Types Yi Hong May 14, 2015.
1 Expressions. 2 Variables and constants linked with operators  Arithmetic expressions Uses arithmetic operators Can evaluate to any value  Logical.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
4. EXPRESSIONS. Display the value of pi, to 5 decimal places, right justified, in 9 columns Read in someone’s height in feet and inches using.
Variables Symbol representing a place to store information
Module B - Computation1/61 Module-B-Computation Variables Basic Memory Operations Expressions.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Chapter 3 The New Math. C++ Data Types simple integral charshort intlong bool floating float double Long double enum address pointer reference structured.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Introduction to Programming Lesson 3. #include #include main ( ) { cout
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
Conversion Check your class notes and given examples at class.
Arithmetic Expressions
Relational Operations
Variable Symbol represents a place to store information
Operators and Expressions
A First Book of ANSI C Fourth Edition
Conversion Check your class notes and given examples at class.
Lecture3.
CSCE 206 Lab Structured Programming in C
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

CGS 3460 Servers n rain.cise.ufl.edu n sand.cise.ufl.edu n shine.cise.ufl.edu n thunder.cise.ufl.edu n storm.cise.ufl.edu

CGS 3460 Variables Continued Getting Input & Operators

CGS 3460 Making calculations n We know the different data types lint lfloat ldouble lchar n How do we transform data into results

CGS 3460 Casting - Implicit n int x = 7.9; n int x = -3.9; n float y = 7; n float y = -65; n char c = 123; n int x = ‘7’ x = 7 x = -3 y = 7.0 y = c = ‘{‘ x = 55 ASCII TABLE

CGS 3460 Casting - Explicit n int x = (int)7.9; n int x = (int)-3.9; n float y = (float)7; n float y = (float)-65; n char c = (char)123; n int x = (int)‘7’ x = 7 x = -3 y = 7.0 y = c = ‘{‘ x = 55 ASCII TABLE

CGS 3460 Operations for int type n Declaration int x, y, z; n Assignment ly = 10; lz = 6; n Calculation lPlus: + x = y + z; lMinus: - x = y – z; lMultiply: * x = y * z; lDivide: / x = y / z; lModulus x = y % z; result of y/z will be truncated

CGS 3460 Integer math - Examples n n 6 * 8 n 4 – 12 n 10 / 3 n 3 / 8 n 14 / 7 n 24 / 5 n 24 % 6 n 22 % 7 n 23 % 8 n 4 % 5 n -7 %

CGS 3460 Integer math – More Examples n 20 % 5 n 20 / 5 * 5 n 24 % 5 n 24 / 5 * 5 n / 10 n %

CGS 3460 float: single-precision Variables n For values containing decimal 3., 125.8, -0.1 lScientific notation 2.25e-3 = 2.25 * = Use e or E for exponent lno commas

CGS 3460 float Variables - II n Ranges lIEEE floating-point standard e = 8, f = 23 ±3.4×10 38

CGS 3460 Operations for float type n Declaration float x, y, z; n Assignment ly = 10.00; lz = 5.8; n Calculation lPlus: + x = y + z; lMinus: - x = y – z; lMultiply: * x = y * z; lDivide: / x = y / z; result of y/z will NOT be truncated

CGS 3460 Floating point math - Examples n n 6.5 * 8.0 n 4.2 – 12.3 n 10.0 / 3.0 n 4.0 / 8.0 n 24.0 /

CGS 3460 Mixed arithmetic - Examples n n 6.5 * 8 n 4 – 12.3 n 10 / 3.0 n 4.0 / 8 n 24 /

CGS 3460 Example – I #include int main() { int a, b, c; float f; a = 10; b = 20; c = a/b; printf(“%i / %i = %i\n”, a, b, c); f = a/b; printf(“%i / %i = %f\n”, a, b, f); } 10 / 20 = 0 10 / 20 =

CGS 3460 Example – II #include int main() { int a; float f, g, h; f = 10.0; g = 20.0; a = f/g; printf(“%f / %f = %i\n”, f, g, a); h = f/g; printf(“%f / %f = %f\n”, f, g, h); } / = / =

CGS 3460 Assignment Operators n Join the arithmetic operators lFormat: op= n Examples: count = count + 10; count += 10; count = count - 5; count -= 5; a /= b + c; a = a / (b + c);

CGS 3460 Unary Operators n Unary plus / minus l+ / - lExample: -a n Unary increment/decrement l++ / -- M = M + 1; M += 1; ++M; M++;

CGS 3460 Example – III #include int main() { int m = 0; //m is 0 at this point printf(“m post increment: %i\n”, m++); //now m is 1 printf(“m pre increment : %i\n”, ++m); //now m is 2 } m post increment: 0 m pre increment : 2

CGS 3460 Arithmetic Operators n add: +, minus: -, multiply: *, divide: /, modulus: % n Parentheses (grouping): ( ) n Unary plus / minus l+ l- n Unary increment/decrement l++ l--

CGS 3460 c =( * b ) Operator Precedence n Precedence lOperators with higher precedence are evaluated first lOperators with same precedence are evaluated from left to right lIn decreasing precedence ( ) unary increment (++), unary decrement (--) unary plus (+), unary minus (-) multiply (*), divide(/), modulus(%) add(+), minus(-) assignment (=) n Order for lc = -a * b la + b * c / d (-a) (b * c) ( / d )(a + )

CGS 3460 Operator Return Types (z = x ? y) xyz int float intfloat intfloat

CGS 3460 How do we get data n We know how to turn the data into “useful information” n How do we get the data from the user?

CGS 3460 Getting Input n Need input from user lscanf Same format as printf, except put “&” in front of variable names scanf(“%i”, &count); “&” means the "address of“ to store whatever the user enters into the memory address where number is stored Leaving out the & will cause your program to work incorrectly! Exception: double uses %lf in scanf and %f in printf

CGS 3460 Example-III #include int main() { int x, y; printf("What is the value for x? \n"); scanf("%i", &x); //read the input //calculate (x-1)^ y = (x-1)*(x-1) + 10; //print the output printf("The result is: %i\n", y); return 0; } What is the value for x? 7 The result is: 46

CGS 3460 Example-IV Half your age plus 7 #include int main() { float age; printf(“How old are you?\n"); scanf("%f", &age); printf(“You can date someone %f years old or older.\n", 0.5 * age + 7); return 0; } How old are you? 26 You can date someone years old or older.