Introduction to Computer Systems Chapter 15

Introduction to Computer Systems Chapter 15 - Chapter 15...

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

View Full Document Right Arrow Icon
Chapter 15 15.1 a. #include <stdio.h> int main() { int i = 1; int sum = 0; while(i < 11) { sum = sum + i; ++i; } printf("%d\n",sum); } b. #include <stdio.h> int main() { int i; int sum = 0; for (i = 0; i <= 10; ++i) sum = sum + i; printf("%d\n",sum); } c. #include <stdio.h> int main() { int i = 0; int sum = 0; while(i < 11) sum = sum + i++; printf("%d\n",sum); } d. #include <stdio.h> int main() { int i = 0; int sum = 0; for(i = 0; i <= 10 ;) sum = sum + i++; printf("%d\n",sum); }
Background image of page 1

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

View Full Document Right Arrow Icon
15.3 #include <stdio.h> main() { int smallestNumber; int nextInput; scanf("%d",&nextInput); /* We need to set the initial value of smallestNumber to something other than 0 as in the original code */ smallestNumber = nextInput; while (nextInput != -1) { if (nextInput < smallestNumber) smallestNumber = nextInput; scanf("%d",&nextInput); } if (smallestNumber != -1) printf("The smallest number is %d\n",smallestNumber); else printf("No numbers entered.\n"); } 15.5 a. (2,3) (2,4) (3,4) (2,5) (3,5) (4,5) (2,6) (3,6) (4,6) (5,6)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 4

Introduction to Computer Systems Chapter 15 - Chapter 15...

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

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