CSC231 Homework 3

From dftwiki3
Revision as of 13:59, 24 September 2008 by Thiebaut (talk | contribs) (Problem #2)
Jump to: navigation, search

<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" />

Back to CSC231 Main Page


Assignment #3

This assignment is due on Wednesday Oct. 1st, at 11:59 p.m. plus one minute.

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.

Problem #2

stay tuned...