ARITHMETICAL OPERATIONS

 

Problem # 1

 

Complete the following program by making the assignment: z  =  3x + 2 / y + w2 :

 

                        REAL  W, X, Y, Z

                        W  =  3.0

                        X  =  25.0

                        Y  =  5

                        Z  =  _______________________

                        PRINT*, ‘Z =   ’ , Z

                        END

 

(a)   Run the program. What is the output ?

(b)  Change the Y declaration to INTEGER Y and run the program again. Does the value of Y change ? If it changes, why does it change ?

 

Problem # 2

 

Complete the program below by making the following assignments:

                               ________

                             /  a   +  b

            x  =         /  ΎΎΎΎ

                        \/      2a  -  b

 

                            b2

            y  =       ΎΎ

                           2a

 

            REAL  A, B, X, Y

            A  =  3.5

            B  =  5.0

            X  =  _________________________

            Y  =  _________________________

            PRINT*, ‘ X  =   ’ , X  , ‘ Y  =   ’  ,  Y

            END

(a)   Run the program. What is the output ?

(b)  Change the declaration REAL  A, B, X, Y to INTEGER  A, B, X, Y .Run the program. What is the output ? Why is the output different from that in (a) ?

 

Problem # 3

 

Write a program which will read the length and width of a rectangle and then find its perimeter.

 

Problem # 4

 

Write a program which will read the length and area of a rectangle and then find its perimeter.

Problem # 5

 

Write a program which will read the surface area, length, and width of a closed box and then find its volume.

 

Problem # 6

 

Write a program that reads a weight in pounds and converts the weight to kilograms. One kilogram = 2.2 pounds.

 

The output should be as follows:

 

            The weight in pounds     =   xxxxx

            The weight in kilograms =   xxxxx

 

Problem # 7

 

Write a program that reads a measurement in pounds and converts it to kilograms and ounces. ( 1 kilogram = 2.2046 pounds, 1 kilogram = 35.27 ounces).

 

Use the following data:  80.0

 

Your output should be in the form:

 

            POUNDS                    KILOGRAMS                                   OUNCES

            80.0000000                 36.2877502                             1279.8688965

 

Write a program that reads a measurement in kilowatt-hours (kWh) and converts it to joules and calories. ( 1 kWh = 0.2778 * 10 -6 joules, 1 calorie =  4.19 joules).

 

Use the following data:  5.5

 

Your output should be in the form:

 

            5.5000000  KILOWATT-HOURS  =  1.5278993E-06  JOULES

            5.5000000  KILOWATT-HOURS  =  3.6465377E-07  CALORIES

 

 

Problem # 8

 

Write a program that reads a number of days and computes and prints the corresponding number of weeks and days. One week = 7 days.

 

The output should be as follows:

 

            xxxxx  days    =       xxxxx   weeks   and    xxxxx   days

 

 

Problem # 9

 

Write a program that reads a distance measured  in miles and converts the distance to kilometers. One kilometer = 1.6 mile.

 

The output should be as follows:

 

            The distance in miles         =   xxxxx

            The distance in kilometers =   xxxxx

 

Problem # 10

 

Write a program that reads a number of bits and computes and prints the corresponding number of bytes and bits. One byte = 8 bits.

 

The output should be as follows:

 

            xxxxx  bits    =       xxxxx   bytes   and    xxxxx   bits

           

Problem # 11

 

Write a program which prompts for, and reads an amount in Riyals and converts it into Dollars. Your output should be in the form:

 

            _____________  RIYALS  =  _______________  DOLLARS

 

Where the blank lines are replaced by appropriate numbers.

Note: 1 Dollar = 3.75 Riyals

 

Use the data:

752.00

 

Your output should be:

 

752.0000000 RIYALS = 200.0000000 DOLLARS

 

Problem # 12 

 

The time a man runs one mile is given in minutes and seconds. Write a program that will read this time and compute the speed of the man in meters per second.

 

Use the data:

 

3.0       52.83

 

Note:   1 mile  =  5280 feet

            1 meter = 3.282 feet

 

Problem # 13

 

Write a program to compute the time a car trip takes and the cost of gasoline for that trip. The input to the program is the trip distance in kilometers, the average speed   (kilometer / hour), the number of kilometers travelled on one liter of gasoline, and the cost in Riyals of a liter of gasoline.

 

Problem # 14

 

Write a program which will read the distance between two towns in kilometers, a speed in kilometers per hour and a departure time from one town in hours and minutes (e.g. 13  45). The program then prints the arrival time in hours and minutes at the other town. Assume that the arrival time is always not more than 24 hours.

 

Problem # 15

 

The roots X1 and X2 of a quadratic equation :

     AX2  + BX + C = 0

 

are given by:

                             _____________               

                 -B +  Ö( B2  -   4AC )

   X1  =   ___________________

                              2A

 

                           ______________  

                 -B - Ö( B2   -   4AC )

   X2  =   ___________________

                              2A

 

Write a program which will prompt for and read values for A, B, and C and then compute the roots of the corresponding quadratic equation.

 

Use the following data:

  1.0    3.0    1.0

 

Problem # 16     

 

Write a program that reads the coordinates of two points (X1 , Y1) and (X2 , Y2). and then it finds the distance between the points.

 

NOTE: The distance between the two points is given by:

             ____________________

          Ö (X1 - X2)2 + (Y1 - Y2)2

 

 

Problem # 17

 

Write a program to evaluate and print the value of the following mathematical  function :

 

         f(x,y) = 4x  -  y 3  +   2xy 2

 

Run your program three times to complete the following table:

 

x

y

f(x,y)

3.0

2.0

 

4.0

3.0

 

-5.0

4.0

 

 

Write a program to evaluate and print the value of the following mathematical  function :

 

            f(x,y) = 2x2 - y  +   3

 

Run your program three times to complete the following table:

 

x

y

f(x,y)

3.0

3.0

 

2.0

3.0

 

-4.0

2.0

 

 

Problem # 18

 

Write a program which reads the volume  v of a sphere and then computes the radius r and the surface area s of that sphere.

 

USE THE DATA:  25.0

 

Your output should be in the form:

 

               RADIUS =  1.8136721  CM

               VOLUME =  25.0000000  CM CUBED

               SURFACE AREA = 41.3525085  CM SQUARED

 

  NOTE:     v = 4.0 / 3pr3    ,  s = 4pr2      , p = 3.14159

 

Problem # 19

 

Write a program which reads the volume v of a right circular cylinder of height 3r2 where r is the radius. The program then computes the radius and the surface area s of that cylinder.

 

USE THE DATA: 100.0

 

Your output should be in the form:

 

               RADIUS =  1.8046312  CM

               VOLUME =  100.0000000  CM CUBED

               SURFACE AREA =  55.4129333  CM SQUARED

 

NOTE:

             v  =  3pr 4     ,  s = 3pr3   ,    p = 3.14159

 

Problem # 20

 

Write a program to compute the surface area and the volume of a sphere given its radius.

 

NOTE:

             s = 4pr 2     ,  v = 4.0 / 3pr3   ,    p = 3.14159

 

Use the data:

3.2

 

Your output should be:

 

RADIUS  =  3.2000000  CM

SURFACE AREA  =  128.7313843  CM SQUARED

VOLUME  =  137.3133545  CM CUBED

 

Problem # 21

 

Write a program which reads the surface area s of a right circular cylinder of height     r / Ö 3.0 where r is the radius. The program then computes the radius r and the volume v of that cylinder.

 

Use the data: 155.0

 

Your output should be in the form:

 

RADIUS  =  6.5353451  CM

SURFACE AREA  =  150.0000000  CM SQUARED

VOLUME  =  506.4880371  CM CUBED

 

NOTE:                                 ___                                ___

            v  =  pr 3  /  Ö 3.0  ,     s  =  2pr 2  /  Ö 3.0  ,   p  =  3.14159

 

 

Solution # 1

                                    REAL   POUNDS,  KG

                                    PRINT *,  ‘ Enter the weight in pounds:’

                                    READ *,  POUNDS

                                    KG   =  POUNDS * 2.2

                                    PRINT *, ‘ The weight in pounds      = ‘ , POUNDS

                                    PRINT *, ‘ The weight in kilograms  = ‘ , KG

                                    END

 

Solution # 2

                                    INTEGER   DAYS,  WEEKS, REMDAY

                                    PRINT *,  ‘ Enter the number of days:’

                                    READ *,  DAYS

                                    WEEKS  =  DAYS / 7

                                    REMDAY = DAYS - WEEKS * 7

                                    PRINT *, DAYS, ‘ days   =  ‘, WEEKS, ‘ weeks  and ‘, REMDAY, ‘ days’

                                    END

 

REAL  RIYALS , DOLARS

            PRINT*, ‘ENTER AMOUNT IN RIYALS:’

            READ*, RIYALS

            DOLARS  =  RIYALS / 3.75

            PRINT*, RIYALS , ‘   RIYALS  =   ‘, DOLARS, ‘   DOLLARS

            END

 

      REAL X1 , X2 , A , B , C

      PRINT*,'ENTER THE VALUES OF THE COEFFICIENTS A , B , C'

      READ*, A , B , C

      X1 = ( - B + ( B ** 2 - 4 * A * C ) ** 0.5 ) / ( 2 * A )

      X2 =  ( - B - ( B ** 2 - 4 * A * C ) ** 0.5 ) / ( 2 * A )

      PRINT*,'THE FIRST ROOT =' , X1

      PRINT*,'THE SECOND ROOT =' , X2

      END

Solution # 1

                                    REAL  MILES,  KM

                                    PRINT *,  ‘ Enter the distance in miles:’

                                    READ *,  MILES

                                    KM   =  MILES * 1.6

                                    PRINT *, ‘ The distance in miles          = ‘ , MILES

                                    PRINT *, ‘ The distance in kilometers  = ‘ , KM

                                    END

 

Solution # 2

                                    INTEGER   BITS,  BYTES, REMBIT

                                    PRINT *,  ‘ Enter the number of bits:’

                                    READ *,  BITS

                                    BYTES  =  BITS  /  8

                                    REMBIT = BITS - BYTES *  8

                                    PRINT *, BITS, ‘ bits  =  ‘, BYTES, ‘ bytes  and ‘, REMBIT, ‘ bits’

                                    END