HOMEWORK 03

Directions: When you have the answer to a problem, start blackboard and click on the homework tab. Then look for Homework H3.x, where the x corresponds to your problem. Click on this. Click on "Write Submission", then type in your answer into the Text Submission window. Finally, click on submit.

H3.1. What is the sum of the first ten positive whole numbers? Work this out by hand or using a calculator (1+2+3+ ... + 10).

H3.2. If you have not already done so, read the Programs 01 page. Do program s1.c discussed on that page. Write, save and compile the program file s1.c. What number does the program s1.c compute? Run the compiled program to SEE what number it computes. It should find (but does not) find and print the sum of the first ten positive whole numbers.

H3.3. What change can you make to correct the program?

H3.4. Play computer with the program below. That is, get a piece of paper, and make three rows on it headed by the names of the three variables that the program defines. Below that, put in a screen area. This should look like the blue area in the Play Computer page.

triNum:

sum:

cnt:

Screen---------------------

Now Play Computer! Carry out the program step by step. Each time a value is put into a variable, write the value to the right of the old values. When a value is printed on the screen, write it in the appropriate place in the screen area. When you are done start blackboard. Click on the Homework tab then click on Homework H3.4. Click on Write Submission. Copy what's on your piece of paper into the Text Submission window and click submit.
#include<stdio.h>
int main() {
  int triNum = 1; 
  int sum = 0;
  int cnt = 0;
  while (cnt<6) 
  {
    sum += triNum;
    triNum += 3;
    cnt += 1;
  }
  printf("%d\n", sum);
}

INTEGERS STORED IN VARIABLES

H3.5. Let variable s be declared:

char s;
Suppose s contains the bit pattern 10111000. What is the corresponding decimal value?

H3.6. Let variable s be declared:

char s;
Suppose s contains the bit pattern 01111000. What is the corresponding decimal value?

H3.7. Let variable u be declared:

unsigned char u;
Suppose s contains the bit pattern 10111000. What is the corresponding decimal value?

H3.8. Let variable s be declared:

char s = -100;
Show the bit pattern stored in variable s.

H3.9. What is the 8-bit two's complement of the binary pattern 10101010?

H3.10. What is the 8-bit two's complement of the binary pattern 01011010?