2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.

Slides:



Advertisements
Similar presentations
CS1010 Programming Methodology
Advertisements

True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
IWBAT compare and order positive and negative numbers.
JavaScript Events and Event Handlers 1 An event is an action that occurs within a Web browser or Web document. An event handler is a statement that tells.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
1.3 Console Input And Output academy.zariba.com 1.
Formatting, Casts, Special Operators and Round Off Errors 09/18/13.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Lecture-5 Miscellaneous. Random Numbers Can use ‘rand()’ function declared in the stdlib.h header file The seed for random number generation can be set.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
ENGINEERING 1D04 Tutorial 1. WELCOME! What we’re doing today Who am I How to do well What are computer programs Software Development Cycle Pseudo Code.
Few More Math Operators
Variables, Operators, and Expressions
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Expressions.
Chapter 3 Assignment and Interactive Input.
Chapter 2 - Introduction to C Programming
TMF1414 Introduction to Programming
Functions, Part 2 of 2 Topics Functions That Return a Value
Basic Elements of C++.
1-5 Equations Goals: Solve equations with one variable
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Revision Lecture
Primitive Data, Variables, Loops (Maybe)
Chapter 2 - Introduction to C Programming
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Administrative things
Arithmetic Operator Operation Example + addition x + y
Few More Math Operators
Lexical Elements, Operators, and the C Cystem
A First Book of ANSI C Fourth Edition
Arithmetic Expressions & Data Conversions
Functions, Part 2 of 3 Topics Functions That Return a Value
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
elementary programming
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Unit 3: Variables in Java
Solving Polynomials by Factoring
C++ for Engineers and Scientists Second Edition
DATA TYPES There are four basic data types associated with variables:
Assignment Operators Topics Increment and Decrement Operators
Functions, Part 2 of 3 Topics Functions That Return a Value
Trigonometric Equations
Functions, Part 2 of 3 Topics Functions That Return a Value
Administrative things
Arithmetic Expressions & Data Conversions
Presentation transcript:

2.3 Output Formatting

Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf (“%3d\n”, 25); The number of spaces, “c”, and number of decimals expressed %c.df,

Special Characters Other characters like % must be typed twice to be printed with printf as in printf(“ 50%\n”) \n prints a new line in printf statements Page shows various formatting commands in a nice chart

Cast To force one type of expression into a certain data type – (Type)Expression

Increment and Decrement Operators A common programming operator is to increase a variable by 1. i++ or ++I i-- or --i

Evaluating Evaluating a math expression means assigning values to all variables and testing the result to determine if it is correct. 5 * (X + Y) - 4 * Y / (Z + 6) with X = 2, Y=3, and Z=6

Combo equal sign

Modulus Operator % symbol when it come to math operations divides the numbers and then return the remainder!!! 5%2 will return 1 as answer 7%5 will return 2 as answer 10%5will return 0 as answer 4%5 will return 4 as answer

Different Header Files #include time.h Stdlib.h

Rounding vs. Output Format

Random Number Generator Every Random number generator needs a “Seed”. Some key starting value. This line picks that seed value based off computer clock Sets the variable to a random number generated by rand() Stdlib.h includes the time() function and time.h is used to get system time

Exercises Write a program that reads a time interval in hours, minutes, and seconds, and converts this measurement to hours only. For example, if the inputs values were 13 hours and 15 minutes and 30 seconds, the output should be something like: 13 hours, 15 minutes, 30 seconds is hours The general quadratic formula can be used to solve for the zeroes of a quadratic equation. Write a program which asks the user for values of A, B, and C from a quadratic equation, and then uses the general quadratic formula to solve for the zeroes. Warning: Depending upon the values for A, B, and C, you may get errors or crashes when you run your program. This is okay for this exercise! (a) Create a program generates a random value between 1 and N, where N is an integer specified by the user. (b) Modify your program to allow the user to specify the starting value and the ending value, both integers. (c) Modify your program to allow the user to specify the integer step between values. For example, numbers between -5 and 5 with a step of 2 could be (at random) -5, -3, -1, 1, 3, 5. (d) Modify your program so all values are real (decimal) values.