Simple Question from Stupid Person...

This is a discussion on Simple Question from Stupid Person... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Hi. I have a series of question about a simple hypothetical program. It is part of a test-review sheet, and ...

  1. #1
    Monmouth3
    Guest

    Unhappy Simple Question from Stupid Person...

    Hi. I have a series of question about a simple hypothetical program. It is part of a test-review sheet, and I can't figure it out for the life of me:

    Here's the sim-program:

    GET #
    STORE N1
    GET
    STORE N2
    SUB N1 # subtracts N1 from what's on scratch-pd
    IFPOS A # if s-pad is pos, go to A
    LOAD N1 # load N1 to s-pad
    GOTO DONE
    A LOAD N2
    DONE PRINT
    STOP
    N1 INIT 0
    N2 INIT 0

    Here are the questions:
    (a) If you run this and submit the numbers 1O and 3O in that order, what value will be printed?

    (b) If you run this and submit 10 and 3 in that order, what value will print?

    (c) How could you phrase in plain English what this program does?

    (d) Sketch out a program that will read a sequence of numbers and print the value of how many numbers there were. "Read" should stop when the number 0 is read. This 0 will not be included in the count.

    (e) Write the code for a program that prints the numbers 1, 2, 3, ..., and will loop infinitely.


    Thanks!!!

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Seems to me like you've posted the complete set of questions straight from the sheet. Why don't _you_ try answering them.

    Read the second post in this thread.


    [edit]Also, this isn't C related. I'll leave it here for about 30min, then I'm going to move it to GD.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Monmouth3
    Guest
    OK, so I figured the rest out. However, I still can't figure out how to do the COUNT program. I could program it to ADD a list of consecutive numbers until one of them was zero or until the sum itself was zero, but I am not aware if there is a "COUNT" command or if there is some way to make one function with other basic commands. Any suggestions?

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Which one's the count program? The 4th or 5th?

  5. #5
    Monmouth3
    Guest
    The fourth is the "count" program, though I am also having trouble with #5. This is what I have four COUNT:

    start GET
    IFZERO print
    ADD COUNT
    STORE COUNT
    GOTO start
    print LOAD COUNT
    PRINT
    STOP
    count INIT 0 (to make it zero to start with, I guess)

  6. #6
    Monmouth3
    Guest
    And this is what I have for #5... can anyone tell me if it would work or if this it totally insane and wrong?
    *Write a program that prints the numbers 1, 2, 3, ..., and does not stop, i.e., is an infinite loop.

    start LOAD INTEGER
    ADD 1 INTEGER
    STORE INTEGER
    GOTO print
    print LOAD INTEGER
    PRINT
    GOTO start
    STOP
    INTEGER INIT 0

    (Is that STOP necessary or redundant. And would this program work?)

  7. #7
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    >And would this program work?)

    What the hell language are you trying to write it in?

    > GOTO print
    print LOAD INTEGER

    That GOTO's redundant - there's no reason to tell anything "goto the next line".

    Here's the code (in C - I still don't know what you're trying to do) for #5
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      int count = 1;
      while(1)
      {
        printf("%d\n", count);
        count++;
      }
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rather a stupid question
    By BEN10 in forum C Programming
    Replies: 9
    Last Post: 06-26-2009, 07:17 AM
  2. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 05:43 AM
  3. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  4. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2005, 12:41 AM
  5. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21