Thursday, 6 December 2018

Function and Procedure (QBASIC)


'1.To find the simple interest on the basis of given principal, time and rate.

'Ans:

DECLARE FUNCTION Simple_Interest (P,T,R)

CLS

INPUT " enter principal:"; Principal

INPUT " enter time:"; Time

INPUT "enter rate:"; Rate

Si = Simple_Interest(Principal, Time, Rate)

PRINT " simple interest=Rs.", Si

END

FUNCTION Simple_Interest (x, y, z)

    Si = (x * y * z) / 100

    Simple_Interest = Si

END FUNCTION



'2. To find the rate of interest per annum.

'Ans:

DECLARE function rate()

REM PRINTS rate ON THE BASIS OF GIVEN PRINCIPAL,RATE AND TIME

r = Rate

PRINT r; "%IS THE RATE OF INTEREST PER ANNUM"

END

FUNCTION Rate

    CLS

    INPUT "Enter a principal,time,simple interest"; p, t, si

    r = (si * 100) / (p * t)

    Rate = r

END FUNCTION



'3. To find the time period to get the given interest.

'Ans:

DECLARE FUNCTION Time()

REM Prints time on the basis of given principal rate and simple interest

t = Time

PRINT t; " Years is the time to get given interest"

END

FUNCTION Time

    CLS

    INPUT "Enter a principal, rate , simple interest"; p, r, si

    t = (si * 100) / (r * p)

    Time = t

END FUNCTION



'4. To find out the principal on the basis of given interest rate and time.

'Ans:

DECLARE FUNCTION Principal()

REM prints principal on the basis of given interest,rate AND TIME

COMMON SHARED s, t, r

p = Principal

PRINT "Rs."; p; "is the principal of given"; si, t, r

END

FUNCTION Principal

    CLS

    INPUT " enter interest, Rate and Time"; si, t, r

    p = (si * 100) / (r * t)

    Principal = p

END FUNCTION



'5. Write a program to find out the largest number among ten given numbers.

'Ans:

DECLARE FUNCTION largest(a())

DIM a(10)

CLS

FOR i = 1 TO 10

    INPUT "Enter a number"; a(i)

NEXT

C = largest(a())

PRINT C; "is largest number"

END

FUNCTION largest (a())

    LARGE = a(1)

    FOR I = 2 TO 10

        IF a(I) > LARGE THEN LARGE = a(I)

    NEXT

    largest = LARGE

END FUNCTION








No comments:

Post a Comment

MCQ Question Bank Microsoft PowerPoint