lec1300_6

# lec1300_6 - Robotics Mechatronics Project 1 C PROGRAMMING...

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

1 1 Robotics & Mechatronics Project 1 C PROGRAMMING HES1300 Ali Bab-Hadiashar EN708d 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);

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

lec1300_6 - Robotics Mechatronics Project 1 C PROGRAMMING...

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

View Full Document
Ask a homework question - tutors are online