CSC 253 Lecture 3. Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Sample Test 1 Question. A pattern of binary digits can be interpreted in several different ways. Show how the pattern translates using each of.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
The little language that could Remember C is a “small language”
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Number System Conversions Lecture L2.2 Section 2.3.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Arrays and Strings Gabriel Hugh Elkaim Spring 2013.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Spring 2005, Gülcihan Özdemir Dağ Lecture 4, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 4 Outline 4.0 Reading.
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
CMPE13 Cyrus Bazeghi Chapter 18 I/O in C. CMPE Standard C Library I/O commands are not included as part of the C language. Instead, they are part.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Review of Lectures 6, 7, 8 and 10. Compilation (1) Compilation translates your source code (in the file hello_world.c) into object code (machine dependent.
Adv. UNIX:io/91 Advanced UNIX v Objectives of these slides: –look in some detail at standard input and output in C Special Topics in Comp.
CSI2172
Looping and Counting Lecture 3 Hartmut Kaiser
Lecture 13 Transition from Fortran to C Yi Lin Feb 27, 2007.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
CS115 FALL Senem KUMOVA-METİN1 The Fundamental Data Types CHAPTER 3.
Expressions and Operators in C. Expressions and Operators Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); Two types: – Function calls – The expressions.
Variables Symbol representing a place to store information
Sample Test 1 Question This one includes ASCII.. Sample Test 1 Question Show how the pattern translates using each of the following interpretations.
CS 125 Lecture 9 Martin van Bommel. Output printf used to display integers, reals (floats and doubles), and strings printf(” control string ”, exp 1,
Expression and Operator. Expressions and Operators u Examples: 3 + 5; x; x=0; x=x+1; printf("%d",x); u Two types: –Function calls –The expressions formed.
Unary, Binary, logical Operations, Explicit type conversion Lecture 6 Instructor: Haya Sammaneh.
C is a high level language (HLL)
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 2 : August 28 webpage:
Binary numbers. Primary memory Memory = where programs and data are stored – Unit = bit “BIT” is a contraction for what two words? Either a 1 or a 0 (because.
Chapter 18 I/O in C Original slides from Gregory Byrd, North Carolina State University Modified slides by C. Wilcox, Y. Malaiya Colorado State University.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Topic: Binary Encoding – Part 1
Lecture 3 Expressions, Type Conversion, Math and String
Introduction to programming in java
A bit of C programming Lecture 3 Uli Raich.
ECE Application Programming
TMF1414 Introduction to Programming
Chapter 3: I/O Management
EPSII 59:006 Spring 2004.
Chapter 18 I/O in C.
Variable Symbol represents a place to store information
What to bring: iCard, pens/pencils (They provide the scratch paper)
Register Use Policy Conventions
Fundamental Data Types
Input and Output Lecture 4.
Chapter 08- printf and scanf
CSI 121 Structured Programming Language Lecture 7: Input/Output
توابع ورودي-خروجي.
Lecture 13 Input/Output Files.
CSCI206 - Computer Organization & Programming
While Loop Design ENGI 1020 Fall 2018.
Fundamental Data Types
Programming Language C Language.
Binary multiplication
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Lecture 3 Expressions, Type Conversion, and string
Recursive example 1 double power(double x, int n) // post: returns x^n
Data in a C++ Program Numeric data and character data
ECE 120 Midterm 1 HKN Review Session.
Section 6 Primitive Data Types
Presentation transcript:

CSC 253 Lecture 3

Let’s look again at …  the program from the end of the last class.  Here’s the start, and the power function:  the program from the end of the last class.  Here’s the start, and the power function: #include int pow(int base, int exp) { int x = base; int i; for (i = 1; i < exp; i++) x = x*base; return x; }

Here’s the main program  int main() {  int i;  int x=-2;  long int xx;  printf("The int value of -2 in hex is %x\n",x);  printf("The int value of -2 in octal is %o\n",x);  x=-1;  printf("The int value of -1 in hex is %x\n",x);  printf("The int value of -1 in octal is %o\n",x);  for (i = 1; i < 34; i++) {  xx = pow(2, i);  printf("2^%d -- Unsigned: %u; signed: %i; hex: %x\n", i, xx, xx, xx);  }  xx = pow(2, 31);  printf("xx-1: %i; xx: %i\n", xx-1, xx);  return EXIT_SUCCESS;  int main() {  int i;  int x=-2;  long int xx;  printf("The int value of -2 in hex is %x\n",x);  printf("The int value of -2 in octal is %o\n",x);  x=-1;  printf("The int value of -1 in hex is %x\n",x);  printf("The int value of -1 in octal is %o\n",x);  for (i = 1; i < 34; i++) {  xx = pow(2, i);  printf("2^%d -- Unsigned: %u; signed: %i; hex: %x\n", i, xx, xx, xx);  }  xx = pow(2, 31);  printf("xx-1: %i; xx: %i\n", xx-1, xx);  return EXIT_SUCCESS;

How could we change it to …  stop when the unsigned number was first different from the signed number?  print just the largest int & largest unsigned int?  print the numbers in nice columns?  i  signed value of 2 i  unsigned value of 2 i  octal value of 2 i  hex value of 2 i  stop when the unsigned number was first different from the signed number?  print just the largest int & largest unsigned int?  print the numbers in nice columns? ii  signed value of 2 i  unsigned value of 2 i  octal value of 2 i  hex value of 2 i

Now let’s try character I/O  Write a program to read a character, then print  the character just read, and  its octal value.  Write a program to read a character, then print  the character just read, and  its octal value.

Now string input …  Write a program to read a hex string and print  its character equivalent, and  the string just read  Write a program to read a hex string and print  its character equivalent, and  the string just read

Now let’s write a program to…  print out the sizes of  short int s  int s  long int s  float s  double s  print out the sizes of  short int s  int s  long int s  float s  double s