Wednesday, October 16, 2019

1. Qbasic Program to calculate the average of three numbers

Using FUNCTION…END FUNTION, write a program to calculate the average of three numbers


DECLARE FUNCTION AVERAGE (A, B, C)
CLS
INPUT “ENTER FIRST NUMBER”; A
INPUT “ENTER SECOND NUMBER”; B
INPUT “ENTER THIRD NUMBER”; C
PRINT “AVERAGE OF THREE NUMBERS”; AVERAGE (A, B, C)

FUNCTION AVERAGE (A, B, C)
AVERAGE = (A + B + C) / 3
             END FUNCTION

20 comments:

  1. Replies
    1. This comment has been removed by the author.

      Delete
    2. DECLARE SUB Average(a,b,c)
      CLS
      INPUT"Enter first number";a
      INPUT"Enter second number";b
      INPUT"Enter third number";c
      CALL SUB Average(a,b,c)
      END

      SUB Average(a,b,c)
      Avg=(a+b+c)/3
      PRINT"Average of three numbers=";Avg
      END SUB

      Delete
    3. Fuck you mother fucker

      Delete
    4. this question came in my exam also..

      Delete
  2. Kindly enter values for the variables given

    ReplyDelete
  3. CLS
    INPUT "enter a number"; A
    INPUT "enter a number"; B
    INPUT "enter a number"; C
    INPUT "enter a number"; D
    INPUT "enter a number"; E
    Avg = (A + B + C + D + E / 5)
    PRINT "Average is"; Avg
    END


    This language is easier


    ReplyDelete
  4. Is there any method to input the 10 numbers at once without typing the input statement so many times

    ReplyDelete
  5. input"enter numbers";a,b,c,d,e,f.........
    you can enter as much as you can..

    ReplyDelete
  6. CLS
    INPUT"Enter the first number;"a
    INPUT"Enter the second number;"b
    INPUT"Enter the third number;"c
    INPUT"Enter the fourth number;'d
    INPUT"Enter the fifth number;"e

    Avg=a+b+c+d+e
    PRINT"The average sum of five number is;"Avg
    END

    ReplyDelete
  7. thx for the answer

    ReplyDelete
  8. How do you do it with both defined function and sub procedure? Like asking three numbers and finding average by function method and calculating product by sub method, in the same program?

    ReplyDelete