Class Notes (836,153)
Canada (509,662)
CS 137 (16)
Lecture 4

Programming Lecture 4.docx

3 Pages
67 Views
Unlock Document

Department
Computer Science
Course
CS 137
Professor
Andrew Morton
Semester
Fall

Description
Programming Lecture 4 Loops  while (expression) statement o Executes body 0+ times  do statement while (expression); o Executes body 1+ times o Eg: do { r= a%b; a=b; b=r; } while (r!=0); Functions  Definition o int gcd (int a, int b) { int r= a%b; while (r!=0){ a=b; b=r; r=a%b; } return b; }  Return type: int  Parameters: (int a, int b)  Invocation (function call) o #include ]gcd func definition int main () { printf(“%d\n”, gcd(806,338); printf(“%d\n”, gcd(25,10)+3); return 0; }  Prints 26, 8  The values passed in the function call are called “arguments” o Trace execution  Execution starts in main  Main o   gcd   806, 338   26  printf   ””, 26    gcd   25, 10   5  printf   “”, 8   o  0  Leap year function o bool leap (int year) { if (year%400 == 0) return true; else if (year%100==0) return false; else if (year%4==0) return true; else return false; }
More Less

Related notes for CS 137

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit