O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming Exercises

  1. Write a program that creates an array with 26 elements and stores the 26 lowercase letters in it. Also have it show the array contents.

  2. Use nested loops to produce the following pattern:

    $
    $$
    $$$
    $$$$
    $$$$$
    
  3. Use nested loops to produce the following pattern:

    F
    FE
    FED
    FEDC
    FEDCB
    FEDCBA
    

    Note: If your system doesn't use ASCII or some other code that encodes letters in numeric order, you can initialize a character array to the letters of the alphabet:

    char lets[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    

    Then you can use the array index to select individual letters; for example, lets[0] is 'A', and so on.

  4. Have a program request the user enter an uppercase letter. Use nested loops to produce a pyramid pattern like this:

     A ABA ABCBA ABCDCDA ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required