Introduction to Computer Science - Fall 2009
CSCI
151
Lab 11
Objectives:
loops WHILE and FOR,
SWITCH statement, char, int, float and double type
compiling and executing C code.
Lab 11 includes Lab PRACTICE ONLY
- Change to your CSCI151 directory: cd CSCI151
- Create a new directory lab11 under your CSCI151 directory:
mkdir
lab11
- Change to lab11 directory: cd lab11
Lab Practice
- Program 1: Write a program that reads a sequence of 10 characters and
prints the ASCII value for each character and finds the number of characters that are equal '*'. Compile
and Run
your program. Show me the result.
- Program 2 :
USE SWITCH in this program.
Write a C program menu.c that
will print the program menu. The program prompts the user
to enter
one integer number, this number will be used in the program to indicate
the specific menu choice. You should consider the following choices: input
0 - exit from the menu, 1 - program asks the user to enter 10 integer numbers and the program will find the maximum and the minimum among the
inputs, 2 - program asks the user to
enter the
integer and checks if the input number even or odd, 3 - program asks the user to enter one integer and one real number. The program prints the
real number amount of times that equal to the integer on one line with the space
between the numbers.
Show me the result and submit the printout.
- Problem 3
Use SWITCH in this program
Write a program that prompts the user to enter one character. You have to use switch statement in your program in order to do the
following: if the input character is 'b', the program reads one number of type double and prints this number 5 times on one line,
numbers should be separated by tab. (you should use loop to do it); if the input character is 'd', the program prints the following
rectangle:
aaabbb
bbbaaa
aaabbb
bbbaaa
aaabbb
bbbaaa
you have to use loop to do this (TRY TO MAKE IT AS SHORT AS POSSIBLE),
and if the input character is 'p', the program will find the product of all odd numbers between 1 and 15 (including 15) ( you should
use loop in this part);
if the input character is not 'b', 'd' or 'p', the program will print the input character 5 times on different lines (you should use
loop to do it).