Sams Teach Yourself C in 21 Days

(singke) #1
Basic Program Control 145

6



  1. Is it true that a whilestatement can be used and still get the same results as coding
    aforstatement?

  2. What must you remember when nesting statements?

  3. Can a whilestatement be nested in a do...whilestatement?

  4. What are the four parts of a forstatement?

  5. What are the two parts of a whilestatement?

  6. What are the two parts of a do...whilestatement?


Exercises ........................................................................................................


  1. Write a declaration for an array that will hold 50 type longvalues.

  2. Show a statement that assigns the value of 123.456to the 50th element in the array
    from exercise 1.

  3. What is the value of xwhen the following statement is complete?
    for (x = 0; x < 100, x++) ;

  4. What is the value of ctrwhen the following statement is complete?
    for (ctr = 2; ctr < 10; ctr += 3) ;

  5. How many Xs does the following print?
    for (x = 0; x < 10; x++)
    for (y = 5; y > 0; y--)
    puts(“X”);

  6. Write a forstatement to count from 1 to 100 by 3s.

  7. Write a whilestatement to count from 1 to 100 by 3s.

  8. Write a do...whilestatement to count from 1 to 100 by 3s.
    9.BUG BUSTER:What is wrong with the following code fragment?
    record = 0;
    while (record < 100)
    {
    printf( “\nRecord %d “, record );
    printf( “\nGetting next number...” );
    }
    10.BUG BUSTER:What is wrong with the following code fragment? (MAXVALUESis
    not the problem!)
    for (counter = 1; counter < MAXVALUES; counter++);
    printf(“\nCounter = %d”, counter );


10 448201x-CH06 8/13/02 11:20 AM Page 145

Free download pdf