Introduction to Computer Science

CSCI 152 Introduction to Computer Science
Programming with C - LAB 1 Practice

Skill set for this assignment:

  • Use if, if-else, if - else - if, and while statements; int, double and float variable types.
  • Use an appropriate variable types and casting
  • Understand and implement the Program Development Cycle
  • Write Lab Report for Each Program
Problem 1
Write a program that inputs one integer between 0 and 100 which indicates student's grade. The program outputs the letter equivalent for numeric grade according to the following table:
A: 100 - 90
B: 89 - 75
C: 74 - 65
D: 64 - 60
F: 59 - 0
Your program must print error message if the input is outisde of the valid range.

Do the loop version of this program and input 10 integers between 0 and 100. Each integer indicates the student's grade. The program outputs the letter equivalent for each numeric grade according to the table above.

Problem 2
There is a treasure box with 1 million dollars. The chest has a 3-digit combination lock that opens under the following conditions: the first digit should be equal to the last digit, the second digit should be even, and the sum of all digits should be divisible by 4. Write a program that reads ONE 3-digits integer between 100 and 999. The program checks if the input number opens the chest or not. The output should be YES, if the chest opens, and NO otherwise. Check validity of the input and output the error message in case of invalid input.

Do the loop version and write a program that reads a series of non-negative integers between 100 and 999. The first negative value will terminate the input. For each input, the program checks if the number opens the chest or not. For each input, the output should be YES, if the chest opens, and NO otherwise.

Examples: Inputs: 525 425 515 505
Outputs:
YES NO NO NO

PAY ATTENTION : In my examples I covered ALL possible situations and checked all conditions.

Problem 3 Write a program that inputs a sequence of positive integers, the first non-positive (zero or negative) number will terminate the input. The program finds the number of inputs between 10 and 20 inclusively and their average.
Example:
Input: 7 18 2 3 10 19 -6
Output:
There are 3 numbers between 10 and 20 inclusively
Their average is: 15.666667

Problem 4

Write a program that reads the 9 distinct integers from 1 to 9 and prints them out in the following way: each integer will be printed the number of times equal to its numeric value. Each such repeated output will be printed on a different line. The nine input integers may be input in any order. You may assume that correct input is always given.
See example below.
Example :
Input: 1 2 3 4 5 6 7 8 9
Output:
1
22
333
4444
55555
666666
7777777
88888888
999999999