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 ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.