lec1300_6

lec1300_6 - Robotics & Mechatronics Project 1 C...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 1 Robotics & Mechatronics Project 1 C PROGRAMMING HES1300 Ali Bab-Hadiashar EN708d Abab-hadiashar@swin.edu.au 2 Functions in C c Modular Program c main function (group of calls to functions that perform the required task) c Standard C library(reinventing the wheel) e ANSI C standard library mathematical calculations input/output string manipulation ... 3 Function definition c Multi-input single output!? e Call by value e Call by reference Return-type func-name (parameter list) { declarations; statements; return something; } 4 Function(example) float my_average(int x, int y) { return (float)(x+y)/2.0; } c and n is a positive whole number double my_power(float x, int n) { int j; double result = x; for(j = 1;j < n; j++) result = result * x; (or result *= x;) return result; } n x 5 Prototype and Header file c A prototype is the signature of a function. It provides vital information about the existence, number of inputs and their types and the return type of the function for the compiler. c Every library has a corresponding header file which contains the function prototypes and definition of different data types and constants need by those functions. 6 Prototype (examples) c float my_average(int x, int y); c float my_average(int , int ); c float my_average(int a, int b); c double my_power(float x, int n); c double my_power(float , int ); c double my_power(float a, int b);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 7 Flowchart c Graphical representation of an algorithm c Drawn using geometrical shapes such as ovals , rectangles , etc c indicates the steps to be performed c indicates the order of execution c not particularly helpful in large programs! 8
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

lec1300_6 - Robotics &amp; Mechatronics Project 1 C...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online