# Program4_1 - the second loop counts by 1 starting from the...

This preview shows page 1. Sign up to view the full content.

4.1 Example – Counting until Overflow The following program count until an overflow condition is met. The number displayed is the last number that was added before the number overflowed into the negative side of the number line. Note the algorithm first counts by 10,000 at a time to get to close to the edge of the number line then in counts by 1 at a time. This saves much running time. /////////////////////////////////////////////////////////////////////// // // Author : Dr. Fernando Gonzalez // Date : 5/25/2004 // // Program 4.1 // // This program counts by 10,000 at a time until the integer is so // large that it wrapped around to the negative side. At this point
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // the second loop counts by 1 starting from the last number that // fit into an integer variable. // // Input : None. // Output : The largest integer this computer can represent to // the console. // Assumptions : The largest integer > 10,000. // /////////////////////////////////////////////////////////////////////// #include "stdio.h" int main() { int next, prev; next = 1; prev = next - 1; while (next > prev) { prev = next; next = next + 10000; } next = prev + 1; while (next > prev) { prev = next; next = next + 1; } printf(" The largest integer is %d \n",prev); return 0; }...
View Full Document

## This note was uploaded on 09/16/2011 for the course EGN 3210 taught by Professor Fernando during the Spring '05 term at University of Central Florida.

Ask a homework question - tutors are online