Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 5. Playing with Data Modifiers and Math Functions Getting Controls

Similar documents
6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

Fundamentals of Programming & Procedural Programming

Expressions. Eric McCreath

CT 229 Java Syntax Continued

ECET 264 C Programming Language with Applications

C++ Programming Lecture 11 Functions Part I

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer

Standard Library Functions Outline

Functions. Systems Programming Concepts

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

2 Unit Bridging Course Day 10

Computer Science & Engineering 150A Problem Solving Using Computers

C Functions. 5.2 Program Modules in C

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

4.7a Trig Inverses.notebook September 18, 2014

int main(void) { int a, b, c; /* declaration */

Downloaded from

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Science One Math. Jan

C Program Structures

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries

Welcome. Please Sign-In

Function. specific, well-defined task. whenever it is called or invoked. A function to add two numbers A function to find the largest of n numbers

Science One Math. Jan

Introduction to Functions in C. Dr. Ahmed Telba King Saud University College of Engineering Electrical Engineering Department

Introduction to Programming

Trigonometric Integrals

MYSQL NUMERIC FUNCTIONS

Structured programming

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

2.2 Limit of a Function and Limit Laws

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

Beginning C Programming for Engineers

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Visual Studio. Visual Studio is an extremely complex interactive development environment capable of handling many languages and tools.

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Math 144 Activity #4 Connecting the unit circle to the graphs of the trig functions

1001ICT Introduction To Programming Lecture Notes

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Review of Trigonometry

Product Price Formula extension for Magento2. User Guide

Methods CSC 121 Fall 2014 Howard Rosenthal

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

Introduction to Engineering gii

Structured Programming. Dr. Mohamed Khedr Lecture 4

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura

Methods CSC 121 Fall 2016 Howard Rosenthal

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Chapter 7: Analytic Trigonometry

Check In before class starts:

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Assoc. Prof. Dr. Tansu FİLİK

Maths Functions User Manual

Intrinsic Functions Outline

Exercises C-Programming

Graphing Trigonometric Functions: Day 1

Fundamentals of Computer Programming Using C

A Quick Review of Trigonometry

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design

Trigonometric Functions of Any Angle

8-1 Simple Trigonometric Equations. Objective: To solve simple Trigonometric Equations and apply them

3.1. Chapter 3: The cin Object. Expressions and Interactivity

BSM540 Basics of C Language

TImath.com Algebra 2. Proof of Identity

A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.

MATH EXAM 1 - SPRING 2018 SOLUTION

What did we talk about last time? Math methods boolean operations char operations

Methods CSC 121 Spring 2017 Howard Rosenthal

Lecture 04 FUNCTIONS AND ARRAYS

Math 1330 Test 3 Review Sections , 5.1a, ; Know all formulas, properties, graphs, etc!

Trigonometric Graphs Dr. Laura J. Pyzdrowski

PreCalculus Summer Assignment

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

ANSI C Programming Simple Programs

SUM AND DIFFERENCES. Section 5.3 Precalculus PreAP/Dual, Revised 2017

C++ Overview. Chapter 1. Chapter 2

Section 7.6 Graphs of the Sine and Cosine Functions

Chapter 4 Expression & Operators

Secondary Math 3- Honors. 7-4 Inverse Trigonometric Functions

Sec 4.1 Trigonometric Identities Basic Identities. Name: Reciprocal Identities:

The Sine and Cosine Functions

Chapter 2. Outline. Simple C++ Programs


This is called the horizontal displacement of also known as the phase shift.

Solving for the Unknown: Basic Operations & Trigonometry ID1050 Quantitative & Qualitative Reasoning

Programming in MATLAB

Programming Fundamentals for Engineers Functions. Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. Modular programming.

Chapter 4: Basic C Operators

AP Calculus Summer Review Packet

Goals for This Lecture:

Math 144 Activity #2 Right Triangle Trig and the Unit Circle

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Walt Whitman High School SUMMER REVIEW PACKET. For students entering AP CALCULUS BC

Transcription:

Readin from and Writint to Standart I/O BIL104E: Introduction to Scientific and Engineering Computing Lecture 5 Playing with Data Modifiers and Math Functions Getting Controls

Pointers What Is a Pointer? A pointer is a variable whose value is used to point to another variable.

Calling sin(), cos(), tan() functions For instance, given an angle x in radians, the sin(x) expression returns the sine of the angle: The following formula can be used to convert the value of an angle in degrees into the value in radians: radians = degree * (3.141593 / 180.0).

Calling sin(), cos(), tan() functions 1: /* Using sin(), cos(), and tan() functions */ 2: #include <stdio.h> 3: #include <math.h> 4: 5: main() 6: { 7: double x; 8: 9: x = 45.0; /* 45 degree */ 10: x *= 3.141593 / 180.0; /* convert to radians */ 11: printf("the sine of 45 is: %f.\n", sin(x)); 12: printf("the cosine of 45 is: %f.\n", cos(x)); 13: printf("the tangent of 45 is: %f.\n", tan(x)); 14: return 0; 15: Output: The sine of 45 is: 0.707107. The cosine of 45 is: 0.707107. The tangent of 45 is: 1.000000.

Calling pow() and sqrt() The value of the double variable x is raised to the power of y with the function pow(x,y). the sqrt(x) function returns the non-negative square root of x in the double data type

Calling pow() and sqrt() 1: /* 09L05.c: Using pow() and sqrt() functions */ 2: #include <stdio.h> 3: #include <math.h> 4: 5: main() 6: { 7: double x, y, z; 8: 9: x = 64.0; 10: y = 3.0; 11: z = 0.5; 12: printf("pow(64.0, 3.0) returns: %7.0f\n", pow(x, y)); 13: printf("sqrt(64.0) returns: %2.0f\n", sqrt(x)); 14: printf("pow(64.0, 0.5) returns: %2.0f\n", pow(x, z)); 15: return 0; 16: Output: pow(64.0, 3.0) returns: 262144 sqrt(64.0) returns: 8 pow(64.0, 0.5) returns: 8

Essentials of Counter-Controlled Repetition Getting Controls The if statement The if-else statement The switch statement The break statement The continue statement The goto statement

The if Statement if This is used to decide whether to do something at a special point, or to decide between two courses of action: if (expression) statement; next statent(s) if with one statement. if (expression) { statement1; statement2;... next statent(s) if with more than one statements.

The if Statement with else The if-else Statement: if (expression) { statement1; statement2;... else { statement_a; statement_b;...

The if Statement 1: /* 10L02.c Using the if-else statement */ 2: #include <stdio.h> 3: 4: main() 5: { 6: int i; 7: 8: printf("even Number Odd Number\n"); 9: for (i=0; i<10; i++) 10: if (i%2 == 0) 11: printf("%d", i); 12: else 13: printf("%14d\n", i); Output: 14: Even Number Odd Number 15: return 0; 0 1 16: 2 3 4 5 6 7 8 9

The if Statement - nested The if-else Statement: if (expression) { statement1; statement2;... else { statement_a; statement_b;...

The if Statement - nested The nested if-else Statement: if (expression) { Statement(s); if (expression) if (expression) statement else { statement(s); if (expression) { statement(s)

The switch Statement if statements are used when there is more than one decision to be made. The nested if statements will become very complex if there are many decisions that need to be made, however. The general form of the switch statement is switch (expression) { case expression1: statement1; case expression2: statement2;... default: statement-default;

The switch Repetition Structure 1: /* 10L04.c Using the switch statement */ 2: #include <stdio.h> 3: 4: main() 5: { 6: int day; 7: 8: printf("please enter a single digit for a day\n"); 9: printf("(within the range of 1 to 3):\n"); 10: day = getchar(); 11: switch (day){ 12: case `1': 13: printf("day 1\n"); 14: case `2': 15: printf("day 2\n"); 16: case `3': 17: printf("day 3\n"); Output: 18: default: 19: ; 20: 21: return 0; 22: Please enter a single digit for a day (within the range of 1 to 3): 3 Day 3