Difference between revisions of "CSC231 Homework 3"
(→Problem #1) |
|||
Line 20: | Line 20: | ||
<code><pre> | <code><pre> | ||
+ | |||
+ | /* mystery.cpp | ||
+ | // D. T. | ||
+ | // mystery program | ||
+ | // To compile and run this program: | ||
+ | // | ||
+ | // g++ mystery.cpp | ||
+ | // a.out | ||
+ | // | ||
+ | // The output of the program is the following | ||
+ | // | ||
+ | // 27001 | ||
+ | // -31534 | ||
+ | // | ||
+ | // With what positive values were x and y initialized | ||
+ | // at the beginning of the program. Explain why. | ||
+ | // (a short int contains 16 bits) | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> | ||
+ | |||
+ | main() { | ||
+ | |||
+ | short int x = ?????; | ||
+ | short int y = ?????; | ||
+ | |||
+ | |||
+ | x = x+y; | ||
+ | printf( "%d\n", x ); | ||
+ | |||
+ | x = x+y; | ||
+ | printf( "%d\n", x ); | ||
+ | } | ||
</pre></code> | </pre></code> | ||
+ | |||
+ | What two positive numbers are stored in x and y to create the output listed in the header? | ||
+ | |||
+ | Explain your answer. | ||
+ | |||
+ | ==Problem #2== |
Revision as of 13:56, 24 September 2008
<meta name="keywords" content="computer science, assembly language, pentium, exercise, machine language, intel" /> <meta name="description" content="Dominique Thiebaut's Web Page" /> <meta name="title" content="Dominique Thiebaut -- Computer Science" /> <meta name="abstract" content="Dominique Thiebaut's Computer Science Web pages" /> <meta name="author" content="thiebaut at cs.smith.edu" /> <meta name="distribution" content="Global" /> <meta name="revisit-after" content="10 days" /> <meta name="copyright" content="(c) D. Thiebaut 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,2008" /> <meta name="robots" content="FOLLOW,INDEX" />
Contents
Assignment #3
Problem #1
Same problem as we did in class. Below is the mystery program. Its output is listed in the header of the program.
/* mystery.cpp
// D. T.
// mystery program
// To compile and run this program:
//
// g++ mystery.cpp
// a.out
//
// The output of the program is the following
//
// 27001
// -31534
//
// With what positive values were x and y initialized
// at the beginning of the program. Explain why.
// (a short int contains 16 bits)
*/
#include <stdio.h>
main() {
short int x = ?????;
short int y = ?????;
x = x+y;
printf( "%d\n", x );
x = x+y;
printf( "%d\n", x );
}
What two positive numbers are stored in x and y to create the output listed in the header?
Explain your answer.