Introduction to Computer Science II
CSCI 152
Lab 5
Objectives:
one-dimensional arrays of characters
compiling and executing C code.
Lab Practice:
Program 1:
-
Write a C program that reads array of characters up to 15 elements.
The program does the following: (1)finds and prints the
actual
length of the
input (2) finds the frequencies of letters a, b and c (3)finds the most frequent and the
least
frequent
among characters a, b and c
- Compile and run your program
Program 2:
-
Write a C program that reads array of characters up to 15 elements.
The program does the following:
finds the frequencies of all letters and finds the most frequent and the least
frequent character. You can assume that the input consists of lowercase letters only.
- Compile and run your program
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.