Introduction to Computer Science - Fall
2009
CSCI 151
Lab 8
Objectives:
increment and decrement operators
assignment
operators for
abbreviating assignment expressions
loop for
types int, float, double
logic operators
compiling
and executing C code.
Only Lab Practice Today
Create a new directory lab8 under your CSCI151
directory
Save all your work in the directory lab8
- Program 1
- Write a program that reads one float number and one integer
number. The program prints the float number the amount of time that
equals to the input integer numbers. You have to use loop WHILE to
solve this problem.
- Compile and run your program.
- Show me the program
- Program 2
- Write a program sumPositiveEven.c that first reads one
positive
integer that will indicate an amount of input integer number that will
come after that.
The program will read the series of the integer numbers (amount of integer
numbers will be equal
to the first input number) and will find the sum of the positive even
input numbers.
Fore example is the input was 5, 3, -2, 4 -5 6
the program should output 10 (explanation: there are 2 even
positive numbers, 4 and 6, their sum is 10), the first input number, 5,
indicates the amount of the input numbers
that will be entered after
that number.
Your program should use loop
WHILE
- Compile and run your program. Show me the result
- Program 3
- Write a program SumProduct.c that sums and products
a sequence of integers. Assume that the first integer read with
scanf specifies the number of values remaining to be entered.
For example if the input was 4 1 4 2 3, where 4 indicates that
subsequent four values are to be summed and multiplied. The output should
be
sum equals 10
product equals 24
Your program should use loop
WHILE
- Compile and run your program a few times
- Show me the result
- Program 4
- Write a
program
DivThreeOdd.c that
inputs a series of
non-negative
integers, a first negative integer indicates the end of the input
sequence. Assume that the input is not empty.
The program determines and prints the amount of input numbers that are ODD
and
divisible by 3 and their average.
Your program should use loop WHILE
. - compile and run your program to test your results.
- Show me the result
Have a good evening.