Difference between revisions of "CSC231 Homework 6 2015"

From dftwiki3
Jump to: navigation, search
Line 23: Line 23:
 
//
 
//
 
//    g++ mystery.cpp
 
//    g++ mystery.cpp
//    a.out
+
//    ./a.out
 
//
 
//
 
// The output of the program is the following
 
// The output of the program is the following
 
//
 
//
// 27001
+
// 2000000001
// -31534
+
// -1294967294
 
//
 
//
 
// With what positive values were x and y initialized
 
// With what positive values were x and y initialized
 
// at the beginning of the program.  Explain why.
 
// at the beginning of the program.  Explain why.
// (a short int contains 16 bits)
+
// An int contains 32 bits and is coded in 2's complement.
 
*/
 
*/
  
#include <stdio.h>
+
#include <iostream>
  
main() {
+
using namespace std;
  
     short int x = ?????;
+
int main( int argc, char* argv[] ) {
     short int y = ?????;
+
 
 +
     int x = ?????;
 +
     int y = ?????;
  
  
 
     x = x+y;
 
     x = x+y;
     printf( "%d\n", x );
+
     cout << x << endl;
  
 
     x = x+y;
 
     x = x+y;
     printf( "%d\n", x );
+
     cout << x << endl;
 +
 
 +
    return 0;
 
}
 
}
 +
  
 
</source>
 
</source>
Line 68: Line 73:
 
* How many terms if we use long unsigned ints of 64 bits?
 
* How many terms if we use long unsigned ints of 64 bits?
  
Explain carefully how you derive your answers.  Prefered answers are answers that contain a program (in the language of your choice) demonstrating/illustrating in one way or another the answers to the various questions.
+
Explain carefully how you derive your answers.  Preferred answers are answers that contain a program (in the language of your choice) demonstrating/illustrating in one way or another the answers to the various questions.
 
<br />
 
<br />
 
=Problem #3=
 
=Problem #3=
Line 94: Line 99:
 
* What is the last number displayed by the loop?  Why?  Is it a valid power of 2?
 
* What is the last number displayed by the loop?  Why?  Is it a valid power of 2?
 
<br />
 
<br />
* Assume now that we are interested in printing powers of 3.   Is the loop infinite?  Why or why not?  If not infinite, what is the last number printed by the program?
+
* Assume now that we are interested in printing powers of 3, so we replace the multiplication line by "x = x * 3;"   Is the loop infinite?  Why or why not?  If not infinite, what is the last number printed by the program?
 
<br />
 
<br />
 
<br />
 
<br />

Revision as of 18:05, 4 November 2015

--D. Thiebaut (talk) 10:46, 4 November 2015 (EST)


Page under construction!

UnderConstruction.jpg



...