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

Tuesday, February 15, 2022

Looping program using FUNCTION....END FUNCTION

 

Looping program using 

FUNCTION....END FUNCTION


1. Write a program to display the square root of first ten natural numbers.

DECLARE FUNCTION square(d)

CLS

FOR j= 1 to 10

a= square(j)

PRINT "The square root of";j;"=";a

NEXT j

END


FUNCTION square(d)

square=SQR(d)

END FUNCTION

 

2. WAP to enter  a word from the user and then print the word in reverse order. (SLC supplementary 2065)

DECLARE FUNCTION rev$(w$)

CLS

INPUT "Enter a string=";w$

PRINT rev$(w$)

END

FUNCTION rev$(w$)

FOR x= LEN(w$) to 1 STEP -1

R$=r$+mid$(w$,x,1)

NEXT x

Rev$=r$

END FUNCTION

 

3. WAP to display the vowel letters from input string.

DECLARE FUNCTION vow$ (w$)

CLS

INPUT "enter any string"; w$

PRINT vow$(w$)

END

 

FUNCTION vow$ (w$)

FOR x = 1 TO LEN(w$)

m$ = LCASE$(MID$(w$, x, 1))

IF m$ = "a" OR m$ = "e" OR m$ = "i" OR m$ = "o" OR m$ = "u" THEN v$ = v$ + m$

NEXT

vow$ = v$

END FUNCTION

 

 4. WAP to find the total number of vowels letters from input string. (SLC 2069, SEE 2073)

DECLARE FUNCTION vo (n$)

CLS

INPUT "Enter any string:"; w$

PRINT vo(w$)

END

FUNCTION vo (n$)

FOR x = 1 TO LEN(n$)

m$ = UCASE$(MID$(n$, x, 1))

IF m$ = "A" OR m$ = "E" OR m$ = "I" OR m$ = "O" OR m$ = "U" THEN

c = c + 1

END IF

NEXT

vo = c

END FUNCTION

 

5. WAP to display the consonant letters from input string.

DECLARE FUNCTION vow$ (w$)

CLS

INPUT "enter any string"; w$

PRINT vow$(w$)

END

 

FUNCTION vow$ (w$)

FOR x = 1 TO LEN(w$)

m$ = LCASE$(MID$(w$, x, 1))

IF m$ = "a" OR m$ = "e" OR m$ = "i" OR m$ = "o" OR m$ = "u" THEN v$ = v$ + m$ ELSE c$=c$+m$

NEXT

vow$ = c$

END FUNCTION

 

6. WAP to count the consonant letters from input string.

DECLARE FUNCTION vow (w$)

CLS

INPUT "enter any string"; w$

PRINT vow(w$)

END

 

FUNCTION vow (w$)

FOR x = 1 TO LEN(w$)

m$ = LCASE$(MID$(w$, x, 1))

IF m$ = "a" OR m$ = "e" OR m$ = "i" OR m$ = "o" OR m$ = "u" THEN v$ = v$ + m$

NEXT

vow = LEN(w$)-v$

END FUNCTION

 

7. WAP to input any string and display how many words are available in string. (SEE 2074)

DECLARE FUNCTION word(a$)

CLS

INPUT "Enter any string:-";a$

wo=word(a$)

PRINT "Total numbers of words=";wo

END

FUNCTION word(a$)

w=1

FOR x= 1 to LEN(a$)

m$=MID$(a$,x,1)

IF m$=" " THEN

w=w+1

END IF

NEXT x

word=w

END FUNCTION

 

8. WAP to input any string and display the total numbers of characters available in string.

DECLARE FUNCTION char(a$)

CLS

INPUT "Enter any string:";a$

ch=char(a$)

PRINT "Total numbers of characters: ";ch

END

FUNCTION char(a$)

FOR x= 1 to LEN(a$)

c=c+1

NEXT x

char=c

END FUNCTION

 

9. WAP to print input string in alternate capital. Eg. QbAsIc

DECLARE FUNCTION myf$(a$)

CLS

INPUT “Enter a number”; a$

PRINT myf$(a$)

END

FUNCTION myf$(a$)

FOR i = 1 to len(a$)

b$= mid$(a$,i,1)

c= I mod 2

IF c<>0 THEN c$=UCASE(b$)

ELSE

c$=LCASE(b$)

ENDIF

d$=d$+c$

NEXT I

myf$=d$

END FUNCTION

 

10. WAP to enter any number and check whether input number is prime or composite.

DECLARE FUNCTION pc$ (n)

CLS

INPUT "enter any number"; n

PRINT pc$(n)

END

 

FUNCTION pc$ (n)

c = 0

FOR x = 1 TO n

IF n MOD x = 0 THEN c = c + 1

NEXT

IF c = 2 THEN

p$ = "prime no"

ELSE

p$ = "composite no"

END IF

pc$ = p$

END FUNCTION

 

11. WAP to calculate the factorial of input number

DECLARE FUNCTION FACT(N)

CLS

INPUT" Enter any number";C

PRINT FACT(C)

END

FUNCTION FACT(N)

A=1

FOR I=1 TO N

A=A*I

NEXT I

FACT=A

END FUNCTION

 

 

12. WAP to display the input digit in reverse order. (Example: if user input digit 123 then output will be 321)

DECLARE FUNCTION drev (n)

CLS

INPUT "enter any digit"; n

PRINT drev(n)

END

 

FUNCTION drev (n)

WHILE n <> 0

r = n MOD 10

s = s * 10 + r

n = n \ 10

WEND

drev = s

END FUNCTION

 

13. WAP to check whether input digit is palindrome or not. (Palindrome is the digit that looks like same from both side)

DECLARE FUNCTION dpal$ (n)

CLS

INPUT "enter any digit"; n

PRINT dpal$(n)

END

 

FUNCTION dpal$ (n)

m = n

WHILE n <> 0

r = n MOD 10

s = s * 10 + r

n = n \ 10

WEND

IF m = s THEN

d$ = "digit is palindrome"

ELSE

d$ = "digit is not palindrome"

END IF

dpal$ = d$

END FUNCTION

 

 14. WAP to check whether input digit is Armstrong or not. (An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example: 371 is an Armstrong number since 3^3+7^3+1^3=371)

DECLARE FUNCTION arm$ (n)

CLS

INPUT "enter any digit"; n

PRINT arm$(n)

END

 

FUNCTION arm$ (n)

m = n

WHILE n <> 0

r = n MOD 10

s = s + r ^ 3

n = n \ 10

WEND

IF m = s THEN

d$ = "digit is Armstrong"

ELSE

d$ = "digit is not Armstrong"

END IF

arm$ = d$

END FUNCTION

 

 15. WAP to display the sum of even digits

DECLARE FUNCTION even (n)

CLS

INPUT “Enter any number”; n

PRINT even(n)

END

FUNCTION even (n)

S = 0

WHILE n < > 0

R = n MOD 10

IF R MOD 2 = 0 THEN S = S + R

N = N \ 10

WEND

EVEN = S

END FUNCTION

 

16. WAP to display the series 1 2 3 4 5 ……..10

DECLARE FUNCTION ser (a)

CLS

a = 0

FOR x = 1 TO 10

PRINT ser(a)

NEXT

END

 

FUNCTION ser (a)

a = a + 1

ser = a

END FUNCTION


17. WAP to display the following series up to 10th term. 1, 8, 27, 64………

DECLARE FUNCTION cube(num)

CLS

FOR i= 1 TO 10

PRINT cube(num)

NEXT

END

FUNCTION cube(num)

T=num^3

Cube=t

END FUNCTION

 

18. WAP to display the series 1, 3, 6, 10, 15….10th term using

DECLARE FUNCTION ser (a, b)

CLS

a = 1: b = 2

FOR i = 1 TO 10

PRINT ser(a, b);

NEXT

END

FUNCTION ser (a, b)

ser = a

a = a + b: b = b + 1

END FUNCTION

 

 

 

2 comments:

  1. Sir in question no.1, Main module is not terminated.

    ReplyDelete
    Replies
    1. Thank u for your response sir, but main module is mentioned there in Q.1.

      Delete

Post Top Ad

Your Ad Spot

Pages