Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, February 12, 2022

Conditional statement using FUNCTION..END FUNCTION

 Conditional statement using 
FUNCTION..END FUNCTION


1) WAP to input any number and display whether that number is odd or even.

DECLARE FUNCTION oe$(n)

CLS

INPUT "Enter any number:-";n

r$=oe$(n)

PRINT r$

END

FUNCTION oe$(n)

r= n MOD 2

IF r=0 THEN

e$="even"

ELSE

e$="odd"

END IF

oe$=e$

END FUNCTION

 

2) WAP to input any number and check whether input number is positive, negative, or natural.

DECLARE FUNCTION po$ (n)

CLS

INPUT "Enter any no"; n

PRINT po$(n)

END

 

FUNCTION po$ (n)

IF n >= 0 THEN po$ = "even"

IF n <= 0 THEN po$ = "negative"

IF n = 0 THEN po$ = "neutral"

END FUNCTION

 

3) WAP to input cost price and selling price and determine whether there is profit or loss.

DECLARE FUNCTION pl$ (cp, sp)

CLS

INPUT "enter cost price"; cp

INPUT "Enter selling price"; sp

PRINT pl$(cp, sp)

END

 

FUNCTION pl$ (cp, sp)

IF cp > sp THEN

pl$ = "loss"

ELSE

pl$ = "profit"

END IF

END FUNCTION

 

4) WAP to input any number from the keyboard and display whether that number is divisible by 3 and 5.

DECLARE FUNCTION divi$(n)

CLS

INPUT "Enter any number:-";n

di$=divi$(n)

PRINT n; di$

END

FUNCTION divi$(n)

r=n MOD 3

r1=n MOD 5

IF r=0 and r1=0 THEN

d$="Divisible by 3 and 5"

ELSE

d$="Not divisible by 3 and 5"

END IF

divi$=d$

END FUNCTION

 

5) WAP to input your age and display whether you can vote or not. [Hint: Minimum age is 18 required for casting the vote.]

DECLARE FUNCTION vote$ (a)

CLS

INPUT "enter age"; a

PRINT vote$(a)

END

 

FUNCTION vote$ (a)

IF a >= 18 THEN vote$ = "You can vote"

IF a < 18 THEN vote$ = "You cant vote"

END FUNCTION

 

6) WAP to input any number and display whether that number is prefect  square or not.

DECLARE FUNCTION square$(n)

CLS

INPUT "Enter any number:-";n

sq=square$(n)

PRINT n; sq$

END

FUNCTION square$(n)

CLS

r=sqr(n)

IF r= INT(r) THEN

s$="Prefect square"

ELSE

s$= "Not prefect square"

END IF

square$=s$

END FUNCTION

 

7) WAP to input any three numbers and display the greatest number.

DECLARE FUNCTION great(a,b,c)

CLS

INPUT "Enter any three numbers:-";a,b,c

g=great(a,b,c)

PRINT "Greatest number=";g

END

FUNCTION great(a,b,c)

IF a>b and a>c then gr=a

IF b>a and b>c then gr=b

IF c> a and c>b then gr=c

great = gr

END FUNCTION

 

8) WAP to input three different strings and display the greatest string among them.

DECLARE FUNCTION long$(a$,b$,c$)

CLS

INPUT "Enter first string:-";a$

INPUT "Enter second string:-";b$

INPUT "Enter third string:-";c$

lo$=long$(a$,b$,c$)

PRINT "The longest string=";lo$

END

FUNCTION long$(a$,b$,c$)

IF LEN(a$) >LEN(b$) and LEN(a$)>LEN(c$) THEN

gr$=a$

ELSEIF LEN(b$)>LEN(a$) AND LEN(b$)>LEN(c$) THEN

gr$=b$

ELSE

gr$=c$

END IF

long$=gr$

END FUNCTION

 

 9) WAP to display the middle number among given three numbers.

DECLARE FUNCTION middle(a,b,c)

CLS

INPUT "Enter any three numbers=";a,b,c

PRINT middle(a,b,c)

END

FUNCTION middle (a,b,c)

IF (a>b AND a<c)  OR  (a<b AND a>c ) THEN ml=a

IF  (b>a AND b<c)  OR (b<a AND b>c) THEN ml=b

IF (c>a AND c<b) OR (c<a AND c>b) THEN ml=c

middle=ml

END FUNCTION

 

10) WAP to input a year and determine whether it is a leap year or not .

DECLARE FUNCTION leap$ (year)

CLS

INPUT "Enter a year"; year

PRINT leap$(year)

END

FUNCTION leap$ (year)

IF (year MOD 4 = 0) AND (year MOD 100 <> 0) THEN

leap$ = "It is a leap year"

ELSE

leap$ = "It is not a leap year"

END IF

END FUNCTION

 

11) WAP to input three sides and check whether it is triangle or not.

DECLARE FUNCTION triangle$ (a, b, C)

CLS

INPUT "Enter three sides"; a, b, C

PRINT triangle$(a, b, C)

END

 

FUNCTION triangle$ (a, b, C)

IF (a + b) > C AND (b + C) > a AND (C + a) > b THEN

t$ = "It is triangle"

ELSE

t$ = "It is not triangle"

END IF

triangle$ = t$

END FUNCTION

 

12) Using user defined function, write a program to input monthly income in parameter then computer annual tax to be paid. The tax rate is 15% if annual income is above Rs. 200000, otherwise tax rate is 1%.

DECLARE FUNCTION TAX(I)

CLS

INPUT “Enter monthly income”; I

PRINT “Tax to be paid=”; TAX(I)

END

FUNCTION TAX(I)

A=I*12

IF A>200000 THEN

TAX=15/100*A

ELSE

TAX=1/100*A

END IF

END FUNCTION

 

13) WAP to input your age and display the result on the basis of following conditions.

Age

Remarks

Greater then equal to 60

Old

Less than 60 and more than equal to 40

Matured

Less than 40 and more than equal to 18

Youth

Less than 18

Child

 

 DECLARE FUNCTION age$ (a)

CLS

INPUT "enter age"; a

PRINT age$(a)

END

 

FUNCTION age$ (a)

IF a >= 60 THEN

age$ = "old"

ELSEIF a < 60 AND a >= 40 THEN

age$ = "matured"

ELSEIF a < 40 AND a >= 18 THEN

age$ = "youth"

ELSE

age$ = "child"

END IF

END FUNCTION

 

14) WAP to input mark and display the grade according to the condition

Marks

Grade

90 to 100

A+

80 to 90

A

70 to 80

B+

60 to 70

B

50 to 60

C+

40 to 50

C

35 to 40

D

Below 35

NG (Non Grade)

 

DECLARE FUNCTION grade$ (m)

CLS

INPUT "Enter marks"; m

PRINT "Your grade="; grade$(m)

END

 

FUNCTION grade$ (m)

SELECT CASE m

CASE 90 TO 100

g$ = "A+"

CASE 80 TO 89.9

g$ = "A"

CASE 70 TO 79.9

g$ = "B+"

CASE 60 TO 69.9

g$ = "B"

CASE 50 TO 59.9

g$ = "C+"

CASE 40 TO 49.9

g$ = "C"

CASE 35 TO 39.9

g$ = "D"

CASE ELSE

g$ = "NG"

END SELECT

grade$ = g$

END FUNCTION

 


You may also Read:

QBASIC program to check whether the input number is a perfect square or not

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages