{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LEC20080922

# LEC20080922 - Introduction to Computer Programming CSC180...

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

Introduction to Computer Programming September 22, 2008 CSC180 Fall 2008, University of Toronto

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

View Full Document
do-while loop Required readings: chapter 7. Review do-while loop. The loop body is executed at least once. Conditional test is in the end. Example: #include <string.h> void reverse(char s[]); /* convert n to characters in s */ void itoa(int n, char s[]) CSC180 Fall 2008, University of Toronto 1
{ int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n positive */ i = 0; do { /* generate digits in reverse order */ s[i++] = n % 10 + ’0’; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) s[i++] = ’-’; s[i] = ’\0’; reverse(s); } /* reverse string s in place */ void reverse(char s[]) { int c, i, j; for (i = 0, j = strlen(s)-1; i < j; i++, j--) { c = s[i]; CSC180 Fall 2008, University of Toronto 2

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

View Full Document
s[i] = s[j]; s[j] = c; } } CSC180 Fall 2008, University of Toronto 3
Basic data types Table 1: Integer types ( <limits.h> ) Type Min size (bits) Min value Max value char 8 -128 127 unsigned char 8 0 255 short 16 -32,768 32,767 unsigned short 16 0 65,535 int 16 -32,768 32,767 unsigned int 16 0 65,535 long 32 -2,147,483,648 2,147,483,647 unsigned long 32 0 4,294,967,295 sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) CSC180 Fall 2008, University of Toronto 4

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

View Full Document
Example: char c; int x; x = 321; c = x; What’s the value of c ? 65 Table 2: Floating-point types ( <float.h> ) Type Min size (bits) Min positive value Max value precision float 32 1.17549435E-38 3.40282347E+38 6 double 64 2.225073858507E-308 1.797693134862E+308 15 CSC180 Fall 2008, University of Toronto 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern