Programming Exercises

I l @ ve RuBoard

Programming Exercises

Reading about C isn't enough. You should try writing one or two simple programs to see if writing a program goes as smoothly as it looks in this chapter. Here are a few suggestions, but you should also try to think up some problems yourself.

  1. Write a program that uses one printf() call to print your first name and last name on one line, uses a second printf() call to print your first and last name on two separate lines, and uses a pair of printf() calls to print your first and last name on one line. The output should look like this (but using your name):

    Mae West First print statement
    Mae Second print statement
    West Still the second print statement
    Mae West Third and fourth print statements
  2. Write a program to print your name and address.

  3. Write a program that converts your age in years to days. At this point, don't worry about fractional years and leap years.

  4. Write a program that produces this output:

     For he's a jolly good fellow! For he's a jolly good fellow! For he's a jolly good fellow! Which nobody can deny! 

    Have the program use two user -defined functions in addition to main() : one that prints the jolly good message once, and one that prints the final line once.

  5. Write a program that creates an integer variable called toes . Have the program set toes to 10 . Also have the program calculate what twice toes is and what toes squared is. The program should print all three values, identifying them.

  6. Write a program that produces this output:

     Smile!Smile!Smile! Smile!Smile! Smile! 

Have the program define a function that displays the string Smile! once, and have the program use the function as often as needed.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net