CS137 Lecture Notes - Lecture 10: Scilab, Call Stack, C Syntax

54 views4 pages

Document Summary

Functions can be passed as arguments: double f(double x); //f=3x2+3x+3 int main () printf( %g\n , bisect (-10, 10, 0. 001, 100000, f0)); printf( %g\n , bisect (-10, 10, 0. 001, 100000, f1)); return 0; Compound data types: groups several named member variables (fields) //time of day struct tod int hours; int minutes; int main () struct tod now = (16, 50); struct tod later; later. hours = 18; later. minues = 0; printf ( %d:%d\n , now. hours, now. minues); printf( %d:%d\n , later. hours, later. minutes); return 0; // better way, as parameters/arguments void todprint (struct tod when) int main() Program trace (call stack) struct tod later = {18,0}; todprint (later); return 0; Returning structs when. minutes +=minutes; when. hours += hours + whenminutes/60; when. minutes %= 60; when. hours %=24; return when; Example struct tod todaddtime (struct tod when, int hours, int minutes) int main () //18:00 struct tod now={16,50}; now = todaddtime (now, 1, 10); todprint(now); return 0;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents