ECET 264 C Programming Language with Applications

Size: px
Start display at page:

Download "ECET 264 C Programming Language with Applications"

Transcription

1 ECET 264 C Programming Language with Applications Lecture 10 C Standard Library Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology Lecture 10 - Prof. Paul I. Lin 1 Lecture 10- C Standard Library Functions C Standard Library Standard Math library <math.h> Standard Math Function Prototype Examples Using math.h Example 10-1: Using Trigonometry Functions: sin(), cos(), and tan() Ceiling and Floor Functions Trigonometry and Inverse Trigonometric Functions Hyperbolic Functions Logarithm Functions Lecture 10 - Prof. Paul I. Lin 2 1

2 Lecture 10 - C Standard Library Functions (continue) Power and Square Functions Example 10-2: Testing Math Functions Example 10-3: Testing More Math Functions and Program Documentation Standard Utility Library <sdtlib.h> Random Number Generation Functions Examples Using stdlib.h Example 10-4: Using Random Number Generation Function Example 10-5: A Program for Rolling Two Dices Summary Lecture 10 - Prof. Paul I. Lin 3 The C Standard Library Standard C functions, types, and macros of the standard library are declared in standard header files. Headers files can be accessed by use # include <header> Headers must be included outside of any external declaration before the use of any C functions. The standard headers are: <assert.h>, <ctype.h>, <errno.h>, <float.h>, <limit.h>, <local.h>, <math.h>, <setjmp.h>, <signal.h>, <stdarg.h>, <stddef.h>, <stdio.h>, <stdlib.h>, <string.h>, and <time.h> Dscuss only <stdio.h>, <math.h>, <stdlib.h>, <.limit.h>, and <float.h> Lecture 10 - Prof. Paul I. Lin 4 2

3 Standard Math Function Prototype <math.h> - the header file of mathematical functions that declare mathematical functions and macros The C standard mathematics functions, <math.h>, must be included in the C program when using math functions All functions in <math.h> allow the programmer to perform certain common mathematical calculations. Lecture 10 - Prof. Paul I. Lin 5 Standard Math Function Prototype (cont.) All the input arguments and return value from a math function are defined as double floatingpoint number data type by default The argument for trigonometric functions should be in the units of radians. Conversion formula: Angle_radian = angle_degree * (PI/180), where PI is Math function prototype and definition Return value type Argument type double sin(double x); Function name Parameter name Lecture 10 - Prof. Paul I. Lin 6 3

4 Standard Math Functions Prototype (cont.) Standard math functions available for use through header file inclusion #include <math.h> are: sin(x) sine of x cos(x) cosine of x tan(x) tangent of x pow(x, y) x goes to power of y, x^y sqrt(x) square root of x exp(x) exponential function e x log(x) natural logarithm of x (base e) ceil(x) round x to the smallest number not less than x floor(x) round x to the largest number not greater than x And more. Lecture 10 - Prof. Paul I. Lin 7 Example 10-1: Using Trigonometry Functions: sin(), cos(), and tan() Problem Statement: Write a simple C program to explain how to use trigonometry functions sin(), cos(), and tan() functions. Analysis and Requirements: Two symbolic constants are defined using the identity: 360 = 2 radians define variable as double floating-point number type examine the program output by print them using the %1f format specifier for double type. Lecture 10 - Prof. Paul I. Lin 8 4

5 Example 10-1: Using Trigonometry Functions: sin(), cos(), and tan() (cont.) /* trigomath.c */ #include <math.h> #include <stdio.h> #define PI #define Deg_to_Rad PI/180.0 #define Rad_to_Deg 180.0/PI void main(void) { double theta = 45.0; double ysin, ycos, ytan; ysin = sin(theta * Deg_to_Rad); //theta * Deg_to_Rad = 45.0 * PI/180.0 = // 45.0 * /180.0 = // ysin = sin(theta * Deg_to_Rad) = sin( ); Lecture 10 - Prof. Paul I. Lin 9 Example 10-1: Using Trigonometry Functions: sin(), cos(), and tan() (cont.) ycos = cos(theta * Deg_to_Rad); ytan = tan(theta * Deg_to_Rad); } printf("sin(%lf Degree) = %lf\n", theta, ysin); printf("cos(%lf Degree) = %lf\n", theta, ycos); printf("tan(%lf Degree) = %lf\n", theta, ytan); printf("tan(%lf Degree) = %e\n", theta, ytan); Lecture 10 - Prof. Paul I. Lin 10 5

6 Example 10-1 (cont.) Program Output: sin( Degree) = cos( Degree) = tan( Degree) = tan( Degree) = e-001 Lecture 10 - Prof. Paul I. Lin 11 Ceiling and Floor Functions double ceil(double x) Calculate the ceiling of a value returns a smallest integer that is greater than or equal to x. It round up the digits after the decimal points Use ceil(x-0.5) to increase accuracy double floor(double x) returns a largest integer that is less than or equal to x. It round off the digits after the decimal points Use floor(x +0.5) to increase accuracy Lecture 10 - Prof. Paul I. Lin 12 6

7 Trigonometric and Inverse Trigonometric Functions double cos(double x) Cosine function takes the x in radians The result is a value in the range 1.0 to 1.0 double sin(double x) Sine function takes x in radians The result is a value in the range 1.0 to 1.0 double tan(double x) Tangent function takes x in radians The result is a value in the range 1.0 to 1.0 Lecture 10 - Prof. Paul I. Lin 13 Trigonometric and Inverse Trigonometric Functions (cont.) double acos(double x) Arc cosine function accepts x in the range 1 to 1 The result is an angle with value between 0 to double asin(double x) Arc sine function accepts x in the range 1 to 1 The result is an angle with value between - /2 to /2 double atan(double x) Arc tangent function accepts x in the range 1 to 1 The result is an angle with value between - /2 to /2 If x is 0, atan() returns 0 double atan2(double y, double x) The function accepts the argument in the form of y/x. If both y and x parameters are 0, the result is 0 The result is an angle with value between - to Lecture 10 - Prof. Paul I. Lin 14 7

8 Hyperbolic Functions A special class of exponential functions: double cosh(double x) Hyperbolic cosine cosh x = (e x + e -x )/2 double sinh(double x) Hyperbolic sine sinh x = (e x -e -x )/2 double tanh(double x) Hyperbolic tangent tanh x = sinh x/ cos hx Lecture 10 - Prof. Paul I. Lin 15 Logarithm Functions double log(double x) log e x Calculate natural logarithm, of a positive x; if x is negative it returns a NaN (not a number or infinite) double log10(double x) log 10 x Compute logarithm to the base 10 of a positive x Lecture 10 - Prof. Paul I. Lin 16 8

9 Power and Square Root Functions double sqrt(double x) Square root of a nonnegative x or x 1/2 double pow(double x, double y) Calculate x to the y power or x y double exp(double x) Raise e ( ) to the power of x or e x Lecture 10 - Prof. Paul I. Lin 17 Example 10-2: Testing Math Function /* logex.c - Write a program to test various math functions*/ #include <math.h> #include <stdio.h> #define PI void main(void) { double y; printf("log10(1000.0) = %lf\n", log10(1000.0)); printf("log(1000.0) = %lf\n", log(1000.0)); printf("exp(1) = %lf\n", exp(1)); Lecture 10 - Prof. Paul I. Lin 18 9

10 Example 10-2: Testing Math Function (cont.) } printf("pow(2,16) = %8.0lf\n", pow(2.0, 16.0)); printf("sqrt(9) = %lf\n", sqrt(9.0)); printf("ceil( ) = %lf\n", ceil( )); printf("ceil(99.4) = %lf\n", ceil(99.4)); printf("ceil( ) = %lf\n", ceil( )); printf("floor( )= %lf\n", floor( )); printf("floor(99.4) = %lf\n", floor(99.4)); printf("floor( ) = %lf\n", floor( )); Lecture 10 - Prof. Paul I. Lin 19 Example 10-2: Testing Math Function (cont.) Output: log10(1000.0) = log(1000.0) = exp(1) = pow(2,16) = sqrt(9) = ceil( ) = ceil(99.4) = ceil( ) = floor( ) = floor(99.4) = floor( ) = Lecture 10 - Prof. Paul I. Lin 20 10

11 Example 10 3: Testing More Math Functions and Program Documentation Problem Statement As a technical staff, you are asked to test the following math functions and report your finding to other technical staffs in your group. The functions that will be tested are sqrt(), exp(), log(), log10(), fabs(), ceil(), floor(), pow(), fmod(), sin(), cos(), and tan() Lecture 10 - Prof. Paul I. Lin 21 Example 10 3: Testing More Math Functions and Program Documentation (cont.) Analysis We should study the problem statement in details, and should ask at least one additional question for clarification: 1. What is the testing environment? Microsoft Visual Studio.NET running under Windows Vista, Windows XP, Windows 2003, Windows 2000, Linux, etc We should also have a copy of technical info that describes function prototypes. The C Programming Language book by Ritche should be a good desk reference. We need to study the functions under testing: sqrt(), exp(), log(), log10(), fabs(), ceil(), floor(), pow(), fmod(), sin(), cos(), and tan() Lecture 10 - Prof. Paul I. Lin 22 11

12 Example 10 3: Testing More Math Functions and Program Documentation (cont.) /* Testing the math library functions */ #include <stdio.h> #include <math.h> /* function main begins program execution */ int main() { /* calculates and outputs the square root */ printf( "sqrt(%.1f) = %.1f\n", 900.0, sqrt( ) ); printf( "sqrt(%.1f) = %.1f\n", 9.0, sqrt( 9.0 ) ); Lecture 10 - Prof. Paul I. Lin 23 Example 10 3: Testing More Math Functions and Program Documentation (cont.) /* calculates and outputs the exponential function e to the x */ printf( "exp(%.1f) = %f\n", 1.0, exp( 1.0 ) ); printf( "exp(%.1f) = %f\n", 2.0, exp( 2.0 ) ); /* calculates and outputs the logarithm (base e) */ printf( "log(%f) = %.1f\n", , log( ) ); printf( "log(%f) = %.1f\n", , log( ) ); Lecture 10 - Prof. Paul I. Lin 24 12

13 Example 10 3: Testing More Math Functions and Program Documentation (cont.) /* calculates and outputs the logarithm (base 10) */ printf( "log10(%.1f) = %.1f\n", 1.0, log10( 1.0 ) ); printf( "log10(%.1f) = %.1f\n", 10.0, log10( 10.0 ) ); printf( "log10(%.1f) = %.1f\n", 100.0, log10( ) ); /* calculates and outputs the absolute value */ printf( "fabs(%.1f) = %.1f\n", 13.5, fabs( 13.5 ) ); printf( "fabs(%.1f) = %.1f\n", 0.0, fabs( 0.0 ) ); printf( "fabs(%.1f) = %.1f\n", -13.5, fabs( ) ); /* calculates and outputs ceil( x ) */ printf( "ceil(%.1f) = %.1f\n", 9.2, ceil( 9.2 ) ); printf( "ceil(%.1f) = %.1f\n", -9.8, ceil( -9.8 ) ); Lecture 10 - Prof. Paul I. Lin 25 Example 10 3: Testing More Math Functions and Program Documentation (cont.) /* calculates and outputs floor( x ) */ printf( "floor(%.1f) = %.1f\n", 9.2, floor( 9.2 ) ); printf( "floor(%.1f) = %.1f\n", -9.8, floor( -9.8 ) ); /* calculates and outputs pow( x, y ) */ printf( "pow(%.1f, %.1f) = %.1f\n", 2.0, 7.0, pow( 2.0, 7.0 ) ); printf( "pow(%.1f, %.1f) = %.1f\n", 9.0, 0.5, pow( 9.0, 0.5 ) ); /* calculates and outputs fmod( x, y ) */ printf( "fmod(%.3f/%.3f) = %.3f\n", , 2.333, fmod( , ) ); Lecture 10 - Prof. Paul I. Lin 26 13

14 Example 10 3: Testing More Math Functions and Program Documentation (cont.) /* calculates and outputs sin( x ) */ printf( "sin(%.1f) = %.1f\n", 0.0, sin( 0.0 ) ); /* calculates and outputs cos( x ) */ printf( "cos(%.1f) = %.1f\n", 0.0, cos( 0.0 ) ); /* calculates and outputs tan( x ) */ printf( "tan(%.1f) = %.1f\n", 0.0, tan( 0.0 ) ); return 0; /* indicates successful termination */ } /* end main */ Lecture 10 - Prof. Paul I. Lin 27 Example 10 3: Testing More Math Functions and Program Documentation Lecture 10 - Prof. Paul I. Lin 28 14

15 Example 10-3: Program Documentation /************************************************************************/ /* Program Name: ex10-03.c */ /* Programmer: Paul Lin */ /* Date: Oct. 10, 2011 */ /* Version: 1.0 */ /* Description: */ /* This program tests the following math functions sqrt(), exp(), */ /* log(), log10(), fabs(), ceil(), floor(), pow(), fmod(), sin(), cos(), */ /* and tan(). The Windows Visual Studio.NET running under */ /* Windows XP was used to prepare testing source code, and */ /* ran testing cases */ /* */ /* Testing Results: */ /* COPY YOUR TESTING RESULT HERE */ /************************************************************************/ Lecture 10 - Prof. Paul I. Lin 29 Utility Function Prototypes <stdlib.h> - the standard library header file which declares utility functions for number conversion, storage allocation, random number generation, absolute value, etc. Absolute Value Calculation <stdlib.h> Int abs(int x); // Computes absolute value of an integer value long labs(long x); // Computes absolute value of a long integer value double fabs(double x); // Compute absolute value of double float type value Lecture 10 - Prof. Paul I. Lin 30 15

16 Utility Function Prototypes (continue) ASCII strings to Numerical Value Conversion <stdlib.h> double atof(const char *string); Convert ASCII string to float-point number int atoi(const char *string); Convert ASCII string to integer number long atol(const char *string); Convert ASCII string to long integer Lecture 10 - Prof. Paul I. Lin 31 Random Number Generator Functions Random Number Generator Functions - in <stdlib.h>, the standard library function The range of the value of rand function is between 0 and RAND_MAX that is at least 32767, which is the maximum value for a two-byte (i.e. 16 bit) integer. Example: rand() %6 Using the remainder operator (%) in conjunction with rand function to produce integers in the range 0 to 5. Lecture 10 - Prof. Paul I. Lin 32 16

17 Random Number Generator Functions (cont.) #include <stdlib.h> int rand(void) Compute pseudo random number The return number in the range 0 to RAND_MAX Values produced by rand() can be scaled and shifted to produce values in a specific range General equation for scaling and shifting a random number is n = a + rand() % b where a is a shifting value and b is the scaling factor Lecture 10 - Prof. Paul I. Lin 33 Random Number Generator Functions (cont.) #include <stdlib.h> void srand(unsigned int x) The srand() takes an unsigned integer argument and seeds function rand() to produce a different sequence of random numbers for each execution of the problem To reinitialize the generator, use 1 as the seed argument To randomize without the need for entering a seed each time, use srand(time(null)) where function time returns the number of seconds, the time function is in <time.h> Lecture 10 - Prof. Paul I. Lin 34 17

18 Example 10 4: Using Random Number Generation Function /* Shifted, scaled integers produced by 1 + rand() % 6 */ #include <stdio.h> #include <stdlib.h> /* function main begins program execution */ int main() { int i; /* counter */ /* loop 20 times */ for ( i = 1; i <= 20; i++ ) { /* pick random number from 1 to 6 and output it */ printf( "%10d", 1 + ( rand() % 6 ) ); Lecture 10 - Prof. Paul I. Lin 35 Example 10 4: Using Random Number Generation Function /* if counter is divisible by 5, begin new line of output */ if ( i % 5 == 0 ) { printf( "\n" ); } /* end if */ } /* end for */ return 0; /* indicates successful termination */ } /* end main */ Lecture 10 - Prof. Paul I. Lin 36 18

19 Example 10-4: Using Random Number Generation Function: Output Lecture 10 - Prof. Paul I. Lin 37 Example 10 5: A Program for Rolling Two Dices This program rolls two dices using rand() function, computes sum, and determines the winning outcomes: 7 or 11 WON 2, 3, or 12 LOST Other numbers 1, 4, 5, 6, 8, 9, 10 CONTINUE to roll again This program has the following characteristics Use a homemade function rolldice() which contains srand(), rand(), and time() for rolling two dices, and return the sum of the two dices Use enum Status(WON, LOST, CONTINUE) to define a new data type which is a sub-integer type: WON ==0, LOST == 1, and CONTINUE == 2, which enhances the readability Use multiple decision making structures: switch, case, Lecture 10 - Prof. Paul I. Lin 38 19

20 Example 10 5: A Program for Rolling Two Dices (cont.) #include <stdio.h> #include <stdlib.h> #include <time.h> /*contains prototype for function time*/ /* enumeration constants represent game status */ enum Status { CONTINUE, WON, LOST }; int rolldice( void ); /* function prototype */ /* function main begins program execution */ int main() { int sum; /* sum of rolled dice */ int mypoint; /* point earned */ Lecture 10 - Prof. Paul I. Lin 39 Example 10 5: A Program for Rolling Two Dices (cont.) /* can contain CONTINUE, WON, or LOST */ enum Status gamestatus; /*randomize random number generator using current time*/ srand( time( NULL ) ); sum = rolldice(); /* first roll of the dice */ /* determine game status based on sum of dice */ switch( sum ) { /* win on first roll */ case 7: case 11: gamestatus = WON; break; /* lose on first roll */ case 2: case 3: case 12: gamestatus = LOST; break; Lecture 10 - Prof. Paul I. Lin 40 20

21 Example 10 5: A Program for Rolling Two Dices (cont.) /* remember point */ default: gamestatus = CONTINUE; mypoint = sum; printf( "Point is %d\n", mypoint ); break; /* optional */ } /* end switch */ /* while game not complete */ while ( gamestatus == CONTINUE ) { sum = rolldice(); /* roll dice again */ /* determine game status */ if ( sum == mypoint ) /* win by making point */ gamestatus = WON; /* game over, player won */ else { Lecture 10 - Prof. Paul I. Lin 41 Example 10 5: A Program for Rolling Two Dices (cont.) if ( sum == 7 ) /* lose by rolling 7 */ gamestatus = LOST; /* game over, player lost */ } /* end else */ } /* end while */ /* display won or lost message */ if ( gamestatus == WON ) printf( "Player wins\n" ); /* did player win? */ else printf( "Player loses\n" ); /* player lost */ return 0; /* indicates successful termination */ } /* end main */ Lecture 10 - Prof. Paul I. Lin 42 21

22 Example 10 5: A Program for Rolling Two Dices (cont.) /* roll dice, calculate sum and display results */ int rolldice( void ) { int dice1; /* first die */ int dice2; /* second die */ int worksum; /* sum of dice */ dice1 = 1 + ( rand() % 6 ); /* pick random die1 value */ dice2 = 1 + ( rand() % 6 ); /* pick random die2 value */ worksum = dice1 + dice2; /* sum die1 and die2 */ /* display results of this roll */ printf( "Player rolled %d + %d = %d\n", dice1, dice2, worksum ); return worksum; /* return sum of dice */ } /* end function rollrice */ Lecture 10 - Prof. Paul I. Lin 43 Example 10 5: A Program for Rolling Two Dices (cont.) Lecture 10 - Prof. Paul I. Lin 44 22

23 Summary Standard Math.h Library Standard Utility Library <stdlib.h> Examples using Standard math and Utility library Next Storage classes and Scope rules Recursive Functions Standard Input/Output <stdio.h> Standard limits <limits.h> Standard floating-point <float.h> Lecture 10 - Prof. Paul I. Lin 45 Question Answer lin@ipfw.edu Lecture 10 - Prof. Paul I. Lin 46 23

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

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

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

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

6-1 (Function). (Function) !*+!#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x (Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)

More information

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

Functions. Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. Functions Angela Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2009 Fall Outline 5.1 Introduction 5.3 Math Library Functions 5.4 Functions 5.5

More information

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

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

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

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

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

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

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

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

C Functions Pearson Education, Inc. All rights reserved.

C Functions Pearson Education, Inc. All rights reserved. 1 5 C Functions 2 Form ever follows function. Louis Henri Sullivan E pluribus unum. (One composed of many.) Virgil O! call back yesterday, bid time return. William Shakespeare Call me Ishmael. Herman Melville

More information

C Programs: Simple Statements and Expressions

C Programs: Simple Statements and Expressions .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following

More information

Functions and Recursion

Functions and Recursion Functions and Recursion 1 Outline Introduction Program Components in C++ Math Library Functions Functions Function Definitions Function Prototypes Header Files Random Number Generation Example: A Game

More information

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved.

Functions. Computer System and programming in C Prentice Hall, Inc. All rights reserved. Functions In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive. You can either use the built-in library functions or you can create

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

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

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 Functions 1 Function n A program segment that carries out some specific, well-defined task n Example A function to add two numbers A function to find the largest of n numbers n A function will carry out

More information

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

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number Generation

More information

Chapter 3 - Functions. Chapter 3 - Functions. 3.1 Introduction. 3.2 Program Components in C++

Chapter 3 - Functions. Chapter 3 - Functions. 3.1 Introduction. 3.2 Program Components in C++ Chapter 3 - Functions 1 Chapter 3 - Functions 2 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3. Functions 3.5 Function Definitions 3.6 Function Prototypes 3. Header Files 3.8

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number

More information

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

Lecture 3. Review. CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions. Conditions: Loops: if( ) / else switch Lecture 3 CS 141 Lecture 3 By Ziad Kobti -Control Structures Examples -Built-in functions Review Conditions: if( ) / else switch Loops: for( ) do...while( ) while( )... 1 Examples Display the first 10

More information

Calling Prewritten Functions in C

Calling Prewritten Functions in C Calling Prewritten Functions in C We've already called two prewritten functions that are found in the C library stdio.h: printf, scanf. The function specifications for these two are complicated (they allow

More information

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

Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,

More information

Programming in C Quick Start! Biostatistics 615 Lecture 4

Programming in C Quick Start! Biostatistics 615 Lecture 4 Programming in C Quick Start! Biostatistics 615 Lecture 4 Last Lecture Analysis of Algorithms Empirical Analysis Mathematical Analysis Big-Oh notation Today Basics of programming in C Syntax of C programs

More information

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

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 5. Playing with Data Modifiers and Math Functions Getting Controls 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?

More information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Eight: Math Functions, Linked Lists, and Binary Trees Name: First Name: Tutor:

More information

Lecture 14. Daily Puzzle. Math in C. Rearrange the letters of eleven plus two to make this mathematical statement true. Eleven plus two =?

Lecture 14. Daily Puzzle. Math in C. Rearrange the letters of eleven plus two to make this mathematical statement true. Eleven plus two =? Lecture 14 Math in C Daily Puzzle Rearrange the letters of eleven plus two to make this mathematical statement true. Eleven plus two =? Daily Puzzle SOLUTION Eleven plus two = twelve plus one Announcements

More information

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

Programming Fundamentals for Engineers Functions. Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. Modular programming. Programming Fundamentals for Engineers - 0702113 7. Functions Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 Modular programming Your program main() function Calls AnotherFunction1() Returns the results

More information

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

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information. Chapter 3 Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus Lecture 03 - Introduction To Functions Christopher M. Bourke cbourke@cse.unl.edu 3.1 Building Programs from Existing

More information

Computer Science & Engineering 150A Problem Solving Using Computers

Computer Science & Engineering 150A Problem Solving Using Computers Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Stephen Scott (Adapted from Christopher M. Bourke) 1 / 41 Fall 2009 Chapter 3 3.1 Building Programs from Existing Information

More information

Lecture 2:- Functions. Introduction

Lecture 2:- Functions. Introduction Lecture 2:- Functions Introduction A function groups a number of program statements into a unit and gives it a name. This unit can then be invoked from other parts of the program. The most important reason

More information

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

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions Computer Science & Engineering 150A Problem Solving Using Computers Lecture 03 - Functions Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 1 / 1 cbourke@cse.unl.edu Chapter 3 3.1 Building

More information

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

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design What is a Function? C Programming Lecture 8-1 : Function (Basic) A small program(subroutine) that performs a particular task Input : parameter / argument Perform what? : function body Output t : return

More information

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

C Functions. CS 2060 Week 4. Prof. Jonathan Ventura CS 2060 Week 4 1 Modularizing Programs Modularizing programs in C Writing custom functions Header files 2 Function Call Stack The function call stack Stack frames 3 Pass-by-value Pass-by-value and pass-by-reference

More information

Function Call Stack and Activation Records

Function Call Stack and Activation Records 71 Function Call Stack and Activation Records To understand how C performs function calls, we first need to consider a data structure (i.e., collection of related data items) known as a stack. Students

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

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

Assoc. Prof. Dr. Tansu FİLİK Assoc. Prof. Dr. Tansu FİLİK Computer Programming Previously on Bil 200 Midterm Exam - 1 Midterm Exam - 1 126 students Curve: 49,78 Computer Programming Arrays Arrays List of variables: [ ] Computer Programming

More information

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations

Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Tutorial 12 Craps Game Application: Introducing Random Number Generation and Enumerations Outline 12.1 Test-Driving the Craps Game Application 12.2 Random Number Generation 12.3 Using an enum in the Craps

More information

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY DUBLIN CITY UNIVERSITY SEMESTER ONE EXAMINATIONS 2007 MODULE: Object Oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Information Telecommunications Engineering B.Eng.

More information

Beginning C Programming for Engineers

Beginning C Programming for Engineers Beginning Programming for Engineers R. Lindsay Todd Lecture 2: onditionals, Logic, and Repetition R. Lindsay Todd () Beginning Programming for Engineers Beg 2 1 / 50 Outline Outline 1 Math Operators 2

More information

Expressions and operators

Expressions and operators Mathematical operators and expressions The five basic binary mathematical operators are Operator Operation Example + Addition a = b + c - Subtraction a = b c * Multiplication a = b * c / Division a = b

More information

CT 229 Java Syntax Continued

CT 229 Java Syntax Continued CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment

More information

C++ Programming Lecture 11 Functions Part I

C++ Programming Lecture 11 Functions Part I C++ Programming Lecture 11 Functions Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Introduction Till now we have learned the basic concepts of C++. All the programs

More information

Using Free Functions

Using Free Functions Chapter 3 Using Free Functions 3rd Edition Computing Fundamentals with C++ Rick Mercer Franklin, Beedle & Associates Goals Evaluate some mathematical and trigonometric functions Use arguments in function

More information

Standard Library Functions Outline

Standard Library Functions Outline Standard Library Functions Outline 1. Standard Library Functions Outline 2. Functions in Mathematics #1 3. Functions in Mathematics #2 4. Functions in Mathematics #3 5. Function Argument 6. Absolute Value

More information

Methods: A Deeper Look

Methods: A Deeper Look 1 2 7 Methods: A Deeper Look OBJECTIVES In this chapter you will learn: How static methods and variables are associated with an entire class rather than specific instances of the class. How to use random-number

More information

9 C Language Function Block

9 C Language Function Block 9 C Language Function Block In this chapter, we focus on C language function block s specifications, edition, instruction calling, application points etc. we also attach the common Function list. 9-1.Functions

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

Chapter 5 C Functions

Chapter 5 C Functions Chapter 5 C Functions Objectives of this chapter: To construct programs from small pieces called functions. Common math functions in math.h the C Standard Library. sin( ), cos( ), tan( ), atan( ), sqrt(

More information

C++ PROGRAMMING SKILLS Part 3 User-Defined Functions

C++ PROGRAMMING SKILLS Part 3 User-Defined Functions C++ PROGRAMMING SKILLS Part 3 User-Defined Functions Introduction Function Definition Void function Global Vs Local variables Random Number Generator Recursion Function Overloading Sample Code 1 Functions

More information

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

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as

More information

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

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1 Chapter 6 Function C++, How to Program Deitel & Deitel Spring 2016 CISC1600 Yanjun Li 1 Function A function is a collection of statements that performs a specific task - a single, well-defined task. Divide

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Preview from Notesale.co.uk Page 2 of 79

Preview from Notesale.co.uk Page 2 of 79 COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com Page 2 of 79 tutorialspoint.com i CHAPTER 3 Programming - Environment Though Environment Setup is not an element of any Programming Language, it is the

More information

Lecture 04 FUNCTIONS AND ARRAYS

Lecture 04 FUNCTIONS AND ARRAYS Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions

More information

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY DUBLIN CITY UNIVERSITY REPEAT EXAMINATIONS 2008 MODULE: Object-oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering (Year 2 & 3) B.Eng. in Information Telecomms Engineering (Year 2 &

More information

12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 12. Numbers Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Numeric Type Conversions Math Class References Numeric Type Conversions Numeric Data Types (Review) Numeric Type Conversions Consider

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Function I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects

Function I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects Function Input and Output Input through actual parameters Output through return value Only one value can be returned Input/Output through side effects printf scanf 2 tj Function Input and Output int main(void){

More information

ANSI C Programming Simple Programs

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

More information

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

More information

MYSQL NUMERIC FUNCTIONS

MYSQL NUMERIC FUNCTIONS MYSQL NUMERIC FUNCTIONS http://www.tutorialspoint.com/mysql/mysql-numeric-functions.htm Copyright tutorialspoint.com MySQL numeric functions are used primarily for numeric manipulation and/or mathematical

More information

Function I/O. Last Updated 10/30/18

Function I/O. Last Updated 10/30/18 Last Updated 10/30/18 Program Structure Includes Function Declarations void main(void){ foo = fun1(a, b); fun2(2, c); if(fun1(c, d)) { } } Function 1 Definition Function 2 Definition 2 tj Function Input

More information

EAS230: Programming for Engineers Lab 1 Fall 2004

EAS230: Programming for Engineers Lab 1 Fall 2004 Lab1: Introduction Visual C++ Objective The objective of this lab is to teach students: To work with the Microsoft Visual C++ 6.0 environment (referred to as VC++). C++ program structure and basic input

More information

The Math Class (Outsource: Math Class Supplement) Random Numbers. Lab 06 Math Class

The Math Class (Outsource: Math Class Supplement) Random Numbers. Lab 06 Math Class The (Outsource: Supplement) The includes a number of constants and methods you can use to perform common mathematical functions. A commonly used constant found in the Math class is Math.PI which is defined

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

More information

C++ Overview. Chapter 1. Chapter 2

C++ Overview. Chapter 1. Chapter 2 C++ Overview Chapter 1 Note: All commands you type (including the Myro commands listed elsewhere) are essentially C++ commands. Later, in this section we will list those commands that are a part of the

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 8: Methods Lecture Contents: 2 Introduction Program modules in java Defining Methods Calling Methods Scope of local variables Passing Parameters

More information

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.

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. Chapter-12 FUNCTIONS Introduction 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. Types of functions There are two types

More information

Loop Controls, Decision Making, Functions, and Data Array Processing

Loop Controls, Decision Making, Functions, and Data Array Processing 3 Loop Controls, Decision Making, Functions, and Data Array Processing 3-1 Standard Input and Output 3-1 3-2 Standard Mathematics and Utility Functions 3-5 3-3 Flow of Control 3-10 3-4 Decision Making

More information

LAB 7 FUNCTION PART 2

LAB 7 FUNCTION PART 2 LAB 7 FUNCTION PART 2 School of Computer and Communication Engineering Universiti Malaysia Perlis 1 OBJECTIVES 1. To differentiate the file scope and block scope. 2. To write recursive function. 3. To

More information

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

static int min(int a, int b) Returns the smaller of two int values. static double pow(double a, The (Outsource: Supplement) The includes a number of constants and methods you can use to perform common mathematical functions. A commonly used constant found in the Math class is Math.PI which is defined

More information

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

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

Programming in C. Part 1: Introduction

Programming in C. Part 1: Introduction Programming in C Part 1: Introduction Resources: 1. Stanford CS Education Library URL: http://cslibrary.stanford.edu/101/ 2. Programming in ANSI C, E Balaguruswamy, Tata McGraw-Hill PROGRAMMING IN C A

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

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

Introduction to Computers II Lecture 4. Dr Ali Ziya Alkar Dr Mehmet Demirer Introduction to Computers II Lecture 4 Dr Ali Ziya Alkar Dr Mehmet Demirer 1 Contents: Utilizing the existing information Top-down design Start with the broadest statement of the problem Works down to

More information

Operators and Expression. Dr Muhamad Zaini Yunos JKBR, FKMP

Operators and Expression. Dr Muhamad Zaini Yunos JKBR, FKMP Operators and Expression Dr Muhamad Zaini Yunos JKBR, FKMP Arithmetic operators Unary operators Relational operators Logical operators Assignment operators Conditional operators Comma operators Operators

More information

www.thestudycampus.com Methods Let s imagine an automobile factory. When an automobile is manufactured, it is not made from basic raw materials; it is put together from previously manufactured parts. Some

More information

C Program Structures

C Program Structures Review-1 Structure of C program Variable types and Naming Input and output Arithmetic operation 85-132 Introduction to C-Programming 9-1 C Program Structures #include void main (void) { } declaration

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 1, 2015 1 M Environment console M.1 Purpose This environment supports programming

More information

Functions and an Introduction to Recursion Pearson Education, Inc. All rights reserved.

Functions and an Introduction to Recursion Pearson Education, Inc. All rights reserved. 1 6 Functions and an Introduction to Recursion 2 Form ever follows function. Louis Henri Sullivan E pluribus unum. (One composed of many.) Virgil O! call back yesterday, bid time return. William Shakespeare

More information

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 5 Methods rights reserved. 0132130807 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. rights reserved. 0132130807 2 1 Problem int sum =

More information

Methods CSC 121 Fall 2014 Howard Rosenthal

Methods CSC 121 Fall 2014 Howard Rosenthal Methods CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class Learn the syntax of method construction Learn both void methods and methods that

More information

6.5 Function Prototypes and Argument Coercion

6.5 Function Prototypes and Argument Coercion 6.5 Function Prototypes and Argument Coercion 32 Function prototype Also called a function declaration Indicates to the compiler: Name of the function Type of data returned by the function Parameters the

More information

Lecture 9 - C Functions

Lecture 9 - C Functions ECET 264 C Programming Language with Applications Lecture 9 C Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 9- Prof. Paul I. Lin

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User-Defined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover

More information

Intrinsic Functions Outline

Intrinsic Functions Outline Intrinsic Functions Outline 1. Intrinsic Functions Outline 2. Functions in Mathematics 3. Functions in Fortran 90 4. A Quick Look at ABS 5. Intrinsic Functions in Fortran 90 6. Math: Domain Range 7. Programming:

More information

Methods CSC 121 Fall 2016 Howard Rosenthal

Methods CSC 121 Fall 2016 Howard Rosenthal Methods CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods

More information

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

Python Lists: Example 1: >>> items=[apple, orange,100,25.5] >>> items[0] 'apple' >>> 3*items[:2] Python Lists: Lists are Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). All the items belonging to a list can be of different data type.

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

(2-2) Functions I H&K Chapter 3. Instructor - Andrew S. O Fallon CptS 121 (January 18, 2019) Washington State University

(2-2) Functions I H&K Chapter 3. Instructor - Andrew S. O Fallon CptS 121 (January 18, 2019) Washington State University (2-2) Functions I H&K Chapter 3 Instructor - Andrew S. O Fallon CptS 121 (January 18, 2019) Washington State University Problem Solving Example (1) Problem Statement: Write a program that computes your

More information

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I ENGI 1020 - Introduction to Computer Programming M A Y 2 8, 2 0 1 0 R E Z A S H A H I D I Last class Last class we talked about the following topics: Constants Assignment statements Parameters and calling

More information

Single row numeric functions

Single row numeric functions Single row numeric functions Oracle provides a lot of standard numeric functions for single rows. Here is a list of all the single row numeric functions (in version 10.2). Function Description ABS(n) ABS

More information

Tutorial 5. PDS Lab Section 16 Autumn Functions The C language is termed as function-oriented programming

Tutorial 5. PDS Lab Section 16 Autumn Functions The C language is termed as function-oriented programming PDS Lab Section 16 Autumn-2018 Tutorial 5 Functions The C language is termed as function-oriented programming Every C program consists of one or more functions. The concept is based on the divide-and conquer

More information

Computer Programming 6th Week Functions (Function definition, function calls),

Computer Programming 6th Week Functions (Function definition, function calls), Computer Programming 6th Week Functions (Function definition, function calls), Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil-200 loops (do-while, for), Arrays, array operations,

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Department of Computer Science and Information Systems Tingting Han (afternoon), Steve Maybank (evening) tingting@dcs.bbk.ac.uk sjmaybank@dcs.bbk.ac.uk Autumn 2017 Week 4: More

More information

Programming for Engineers Functions

Programming for Engineers Functions Programming for Engineers Functions ICEN 200 Spring 2018 Prof. Dola Saha 1 Introduction Real world problems are larger, more complex Top down approach Modularize divide and control Easier to track smaller

More information

Script started on Thu 25 Aug :00:40 PM CDT

Script started on Thu 25 Aug :00:40 PM CDT Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,

More information

The Math Class. Using various math class methods. Formatting the values.

The Math Class. Using various math class methods. Formatting the values. The Math Class Using various math class methods. Formatting the values. The Math class is used for mathematical operations; in our case some of its functions will be used. In order to use the Math class,

More information