Introduction to Computer Science II
CSCI 152
Lab 5
  

Objectives:
one-dimensional arrays of characters
compiling and executing C code.    Lab Practice:
  • Program 1:
  • Program 2:

  • Program 3
    Write a function int sumASCII(char s[]) that finds the sum of the ASCII values of the elements of the array s. Write a C program that reads a string (use function stringInput that we wrote in class) and finds the sum of the ASCII values of the elements using function sumASCII. Define the size of array using #define statement.
  • Program 4
    Write a program that declares one character array that can hold 20 elements (including '\0'). Define thesize of array using #define statement. The program prints the input string in the following way: each character will be printed the amount of time that corresponds to the index value. The first character will be not printed at all. For example, if the input was
    program
    The output will be
    roogggrrrraaaaammmmmm
    Write a function void funPrint(char s[]) that will perform this strange printing and use this function in your program. The string input should be done by function as well.

  • Program 5
    Write a function int Palindrome (char s[ ]) that returns 1 if s is a palindrome (palindrome is a word, phrase, verse, or sentence that reads the same backward or forward) and 0 otherwise. Examples of palindromes:
    I PREFER PI
    Never odd or even,
    No lemons, no melon.
    Write a program that reads a string (use function stringInput that we wrote in class) and checks if the input string is palindrome or not. Define the size of array using #define statement.