Home Work 1: Data Types, Variables and Expressions

  1. Determine the appropriate variable type and names for the following. Give your justification for choosing the variable type.

    1. a person's age to the nearest year
    2. a person's weight in pounds
    3. the radius of a circle
    4. the cost of an item
    5. the highest grade on a test (assume it is always 100)
    6. the temperature
    7. the distance from the Earth to a star in miles
  2. (Project 1) Exercise 4 in page 21 of your text.

    #include <stdio.h>
    main()
    {
      /* this program displays the result of subtraction
         of one  predefined values  from the other */
       int value1, value2, result;
       value1 = 87;
       value2 = 15;
       result = value1 - value2; 
       printf("The result after subtracting %d from %d = %d \n",
              value1, value2, result);  
    }
  3. (Project 2) Write a program that reads in four test scores, computes the average and displays the result.

    #include <stdio.h>
    main()
    {
      /*this programs reads input thro the key 
       board and computes the average*/
       float score1, score2, score3, score4;
       float average;
       scanf("%f %f %f %f", &score1,&score2,&score3,&score4);
       average = (score1 + score2 + score3 + score4)/4; 
       /*to make sure that the average
         does not get truncated, we have declared
        the scores as float but not integers*/
       printf("The average score of %5.2f %5.2f %5.2f %5.2f 
         is %5.2f\n", score1, score2, score3, score4, average);  
    }
  4. (Project 3) All of you are familiar with wind chill. There is an excellent formula to calculate the wind chill, given the ambient temperature in degrees Fahrenheit and the wind velocity in miles per hour. The formula is reasonable accurate for wind speeds between 5 and 90 MPH, and ambient temperatures between -40 and +90 tex2html_wrap_inline27 F.

    Here is the formula:
    c = ((10.45 + (6.686*sqrt(v))-(o.447*v))/
    22.034*(t-91.4))+91.4

    Here the function ``sqrt'' computes the square root. Write a C program to accept values for velocity and temperature to calculate the wind chill, c and print ``given the temperature ``t tex2html_wrap_inline27 F,'' and the wind velocity ``v,'' the wind chill is ....

    #include <stdio.h>
    #include <math.h>
    main()
    {
      /*program to compute wind chill for a 
        given wind velocity and temperature*/
       float v, t, c;
       scanf("%f %f",&v,&t);
       if ((v >= 5 && v <= 90) && (t >= -40 && t <= 90))
       {
        c = ((10.45 + (6.686*sqrt(v))- (0.447*v))/22.034*(t-91.4))+91.4; 
        printf("given the temperature %f 0F,
             and the wind velocity %f, 
             the wind chill is  %f", v, t, c);   
       }
    }

About this document ...

This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 -html_version 3.0 hw1-sol.tex.

The translation was initiated by Vijay & on Thu Mar 5 10:21:52 EST 1998


Vijay &
Thu Mar 5 10:21:52 EST 1998