LEC20080922 - Introduction to Computer Programming...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Computer Programming September 22, 2008 CSC180 Fall 2008, University of Toronto 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 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 255 short 16-32,768 32,767 unsigned short 16 65,535 int 16-32,768 32,767 unsigned int 16 65,535 long 32-2,147,483,648 2,147,483,647 unsigned long 32 4,294,967,295 • sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) CSC180 Fall 2008, University of Toronto 4 • 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+383....
View Full Document

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto.

Page1 / 16

LEC20080922 - Introduction to Computer Programming...

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

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