CSCI 151 Introduction to Computer Science

CSCI 151 Fall 2009 Assignment 2

The due date is Monday, October 19, 2009. The printout of the programs should be received by 3:50 pm on Monday, October 19, 2009

Please read the instructions on how to compile, run and submit outputs for your C program

Important note: Please, do your own work. Programs which are written in groups are easily identified and will receive grades of 0 for all participants.

Important: Each program has to include the detailed comments. Follow the Lecture examples.

Important: You have to use UNIX/LINUX in this course and in this assignment.

Skill set for this assignment:

  • Understand and implement the Program Development Cycle
  • Use integer and float type of variables and assignment statements
  • Use basic arithmetic operations
  • Use printf and scanf functions
  • Printing strings and special characters
  • Save, run and submit programs

Problem 1 (15 points): Write a C program that first reads one integer. If the integer is even, the program reads any Celsius temperature and outputs the equivalent Fahrenheit temperature. The equation for converting a Celsius temperature to Fahrenheit is

    Fahrenheit=(9*Celsius/5)+32
If the integer is odd, the program reads any Fahrenheit temperature and outputs the equivalent Celsius temperature. The equation for converting a Fahrenheit temperature to Celsius is
    Celsius= (5/9)*(Fahrenheit - 32)

Problem 2 (15 points):
Write a C program that prompts the user to enter one three-digit positive integer. The program first prints the user's full name. The program separates the input number into it's individual digits and prints the digits separated from one another by tab. For example if the input number was 236 the program will print 2    3    6

Problem 3 (15 points):
Write a C program that promts the user to enter one number that indicates the radius of the circle. The program will calculate and print the diameter (2*radius) , circumference (2*pi*radius) and area (pi*radius*radius) of the circle. Use the value 3.14159 for pi.

Problem 4 (15 points):
Write a C program that prompts the user to enter one integer number, and check if the number is greater than 10, less than 10 or equals 10. The program should print an appropriate message for each case. For example, if the input is 3, the output should be: 3 is less than 10; if the input is 16, the output should be: 16 is greater than 10; and if the input is 10 , the output should be: 10 equals 10.

Problem 5 (20 points):
Write a C program that prompts the user to enter four integer numbers. The program will find and print the minimal and maximal value among the four input numbers. For example, if the input is 12 34 -9 0, the program should output: -9 is the minimal value and 34 is the maximal value.

Problem 6 (20 points):
Write a program that reads 3 four-digit integers and calculates the average of the last digits.
Example:
Input: 123 458 895
Output: 5.333333

GOOD LUCK!