Wednesday, October 16, 2019

11. Qbasic Program to calculate distance travelled by a body.


11.      Using FUNCTION, write a program to calculate distance travelled by a body. (Hint: s=ut+ (1/2) at2) 

DECLARE FUNCTION DISTANCE (U, T, A)
CLS
INPUT “ENTER INITIAL VELOCITY”; U
INPUT “ENTER TIME”; T
INPUT “ENTER ACCELARATION”; A
PRINT “DISTANCE TRAVELLED = “; DISTANCE (U, T, A)
END

FUNCTION DISTANCE (U, T, A)
DISTANCE = U * T + 1 / 2 * A * T ^ 2
END FUNCTION

8 comments:

  1. DECLARE FUNCTION D(U,T,A)
    CLS
    INPUT " ENTER INTIAL VELOCITY"; U
    INPUT " ENTER TIME"; T
    INPUT "ENTER ACCELERATION"; A
    G = D(U, T, A)
    PRINT "THE DISTANCE TRAVELLED BY A BODY IS"; G
    END

    FUNCTION D (U, T, A)
    S = U * T + (1 / 2) * A * T ^ 2
    D = S
    END FUNCTION

    I do think it can be done in this way also although your answer and mine rae same but there is a slight difference. Can you please check my answer and say if this is also correct or not . Please reply as fast as possible .

    ReplyDelete
  2. Again sorry spelling mistake its are*

    ReplyDelete
  3. Write a program to calculate and display distance travelled by a car if the initial odometer reading is 3450 and the current odometer reading is 3512.

    ReplyDelete
    Replies
    1. CLS
      PRINT "Volume of a Box Calculator"
      PRINT "--------------------------"

      INPUT "Enter the length of the box: "; length
      INPUT "Enter the width of the box: "; width
      INPUT "Enter the height of the box: "; height

      volume = length * width * height

      PRINT "The volume of the box is: "; volume

      END

      Delete
    2. CLS
      PRINT "Distance Traveled Calculator"
      PRINT "-----------------------------"

      INPUT "Enter the initial odometer reading: "; initialReading
      INPUT "Enter the current odometer reading: "; currentReading

      distance = currentReading - initialReading

      PRINT "The distance traveled by the car is: "; distance; " miles"

      END

      Delete