MODULAR PROGRAMMING (EXERCISE 4)

 


11.

AN

ND

DR

RO

OI

ID

D

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

FOR I= 1 TO LEN(A$)

PRINT MID$(A$,I,2)

NEXT I

END SUB

 

12.

AN

    ND

          DR

               RO

                    OI

                        ID

                             D

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

T=20

FOR I=1 TO LEN(A$)

PRINT TAB(T); MID$(A$,I,2)

T=T+1

NEXT I

END SUB

 

13.

ANDROID

ANDRO

AND

A

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

FOR I= LEN(A$) TO 1 ATEP -2

PRINT LEFT$(A$,I)

NEXT I

END SUB

 

14.

A

AND

ANDRO

ANDROID

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

FOR I=1 TO LEN(A$) STEP 2

PRINT LEFT$(A$,I)

NEXT I

END SUB

 

15.ANDROID

        NDROI

           DRO

               R

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

C=7

T=5

FOR I=1 TO 4

PRINT TAB(T); MID$(A$,I,2)

T=T+1

C=C-2

NEXT I

END SUB

 

16.

        R

      DRO

   NDROI

ANDROID

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “ANDROID”

C=1

T=30

FOR I= 4 TO 1 STEP -1

PRINT TAB(T); MID$(A$,I,C)

T=T-1

C=C+2

NEXT I

END SUB

 

17.

     *

   ***

 

  *****

*******

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “*******”

C=1

T=20

FOR I= 4 TO 1 STEP -1

PRINT TAB(T); MID$(A$, I, C)

T=T-1

C=C+2

NEXT I

END SUB

 

18.

******* 

  *****

     ***

       *

ANS:

DECLARE SUB PATTERN()

CLS

CALL PATTERN

END

SUB PATTERN

A$= “*******”

C=7

T=20

FOR I=1 TO 4

PRINT TAB(T); MID$(A$,I,C)

T=T+1

C=C-2

NEXT I

END SUB

 

#WRITE A PROGRAM TO PRINT THE REVERSED STRING.

DECLARE SUB REV(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL REV(A$)

END

SUB REV(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)+B$

NEXT I

PRINT “REVERSED STRING IS=”;B$

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED STRING IS PALINDROME OR NOT.

DECLARE SUB PAL(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL PAL(A$)

END

SUB PAL(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)+B$

NEXT I

IF A$=B$ THEN

PRINT “THE STRING IS PALINDROME”

ELSE

PRINT “THE STRING IS NOT PALINDROME”

END IF

END SUB

 

#WRITE A PROGRAM TO PRINT THE TOTAL NUMBER OF VOWELS PRESENT IN A GIVEN STRING.

DECLARE SUB VOW(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL VOW(A$)

END

SUB VOW(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “A”, “E”, “I”, “O”, “U”

V=V+1

END SELECT

NEXT I

PRINT “TOTAL NUMBER OF VOWELS=”;V

END SUB

 

#WRITE A PROGRAM TO PRINT THE TOTAL NUMBER OF CONSTANTS PRESENT IN A GIVEN STRING.

DECLARE SUB CON(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL CON(A$)

END

SUB CON(A$)

FOR I=A TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

IF C$<>“A” AND C$<> “E” AND C$<> “I” AND C$<> “O” AND C$<> “U” THEN C=C+1

NEXT I

PRINT “TOTAL NUMBER OF CONSTANTS=”;C

END SUB

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF VOWELS AND CONSONANTS PRESENT IN A GIVEN STRING.

DECLARE SUB COUNT(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL COUNT(A$)

END

SUB COUNT(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “A”, “E”, “I”, “O”, “U”

V=V+1

CASE ELSE

C=C+1

END SELECT

NEXT I

PRINT “TOTAL  NUMBER OF VOWELS”;V

PRINT “TOTAL NUMBER OF CONSONANTS=”;C

END SUB

 

#WRITE A PROGRAM TO PRINT THE VOWEL CHARACTERS PRESENT IN A GIVEN STRING.

DECLARE SUB VOW(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL VOW(A$)

END

SUB VOW(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$                                   

CASE “A”, “E”, “I”, “O”, “U”

PRINT “VOWEL CHARACTERS=”;C$

END SELECT

NEXT I

END SUB

 

#WRITE A PROGRAM TO PRINT THE CONSONANTS PRESENT IN A GIVEN STRING.

DECLARE SUB CON(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL CON(A$)

END

SUB CON(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

IF C$<> “A” AND C$<> “E” AND C$<> “I” AND C$<> “O” AND C$<>“U”

THEN

PRINT “CONSONANTS CHARACTER IS=”;C$

END IF

NEXT I

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS ARMSTRONG OR NOT.

DECLARE SUB ARM(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL ARM(N)

END

SUB ARM(N)

A=N

WHILE A<>0

R=A MOD 10

S=S+R^3

A=A\10

WEND

IF N=S THEN

PRINT “THE NUMBER IS ARMSTRONG”

ELSE

PRINT “THE NUMBER IS NOT ARMSTRONG”

END IF

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE SUM OF DIGITS OF A NUMBER.

DECLARE SUB SUM(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R=N MOD 10

S=S+R

N=N\10

WEND

PRINT “SUM OF DIGITS=”;S

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE PRODUCT OF DIGITS OF A NUMBER.

DECLARE SUB PRO(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL PRO(N)

END

SUB PRO(N)

P=1

WHILE N<>0

R=N MOD 10

P=P*R

N=N\10

WEND

PRINT “PRODUCT OF DIGITS=”;P

END SUB

 

#WRITE A PROGRAM TO PRINT THE REVERSE OF A NUMBER.

DECLARE SUB REV(A)

CLS

INPUT “ENTER ANY  NUMBER”;A

CALL REV(A)

END

SUB REV(A)

WHILE A<>0

R=A MOD 10

S=S*10+R

A=A\10

WEND

PRINT “THE REVERSED NUMBER IS=”;S

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PALINDROME OR NOT.

DECLARE SUB PAL(A)

CLS

INPUT “ENTER ANY NUMBER”;A

CALL PAL(A)

END

SUB PAL(A)

N=A

WHILE N<>0

R=N MOD 10

S=S*10+R

N=N\10

WEND

IF A=S THEN

PRINT “THE NUMBER IS PALINDROME”

ELSE

PRINT “THE NUMBER IS NOT PALINDROME”

END IF

END SUB

 

#WRITE A PROGRAM TO PRINT THE MULTIPLICATION TABLE OF ANY GIVEN NUMBER UPTO 10THTERMS.

DECLARE SUB MUL(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL MUL(N)

END

SUB MUL(N)

PRINT “THE MULTIPLICATION TABLE OF”;N;”IS”

FOR I=1 TO 10

PRINT N; “*”; I; “=”; N*I

NEXT I

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PRIME OR COMPOSITE.

DECLARE SUB CHECK(N)

CLS

INPUT “ENTER ANY NUMBER”

CALL CHECK(N)

END

SUB CHECK(N)

FOR I=1 TO N

IF N MOD I=0 THEN C=C+1

NEXT I

IF C=2 THEN

PRINT “THE NUMBER IS PRIME”

ELSE

PRINT “THE NUMBER IS COMPOSITE”

END IF

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE NUMBER IS A PERFECT SQUARE OR NOT.

DECLARE SUB PERSQ(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL PERSQ(N)

END

SUB PERSQ(N)

S=SQR(N)

IF S=INT(S) THEN

PRINT “THE NUMBER IS PERFECT SQUARE”

ELSE

PRINT “THE NUMBER IS NOT PERFECT SQUARE”

END IF

END SUB

 

#WRITE A PROGRAM TO COUNT THE WORDS PRESENT IN A SENTENCE.

DECLARE SUB COUNT(N$)

CLS

INPUT “ENTER A SENTENCE”;N$

CALL COUNT(N$)

END

SUB COUNT(N$)

C=1

FOR I=1 TO LEN(N$)

B$=MID$(N$,I,1)

IF B$= “ ”  THEN C=C+1

NEXT I

PRINT “TOTAL NUMBER OF WORDS IN A SENTENCE IS=”;C

END SUB

 

#WRITE A PROGRAM TO PRINT THE STRING WITH ALTERNATE CASES. [IF INPUT IS “computer”, OUTPUT SHOULD BE “CoMpUtEr”].

DECLARE SUB ALT(N$)

CLS

INPUT “ENTER ANY STRING”;N$

CALL ALT(N$)

END

SUB ALT(N$)

FOR I=1 TO LEN(N$)

B$=MID$(N$,I,1)

IF I MOD 2=0 TEHN

B$=LCASE$(B$)

ELSE

B$=UCASE$(B$)

END IF

ALT$=ALT$+B$

NEXT I

PRINT “THE STRING WITH ALTERNATE CASES=”;ALT$

END SUB

 

#WRITE A PROGRAM TO CHANGE THE CASE OF INDIVIDUAL CHARACTERS INPUT STRING. [IF INPUT IS “cOmPuTeR”, OUTPUT SHOULD BE “CoMpUtEr”]

DECLARE SUB CHANGE(N$)

CLS

INPUT “ENTER ANY STRING”;N$

CALL CHANGE(N$)

END

SUB CHANGE(N$)

FOR I=1 TO LEN(N$)

A$=MID$(N$,I,1)

IF A$=UCASE$ THEN

A$=LCASE$(A$)

ELSE

A$=UCASE$(A$)

END IF

RESULT$=RESULT$+A$

NEXT I

PRINT “OUTPUT STRING IS =”;RESULT$

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE SUM OF EVEN DIGITS OF A NUMBER.

DECLARE SUB SUM(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R=N MOD 10

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

N=N\10

WEND

PRINT “SUM OF EVEN DIGITS OF A NUMBER=”;S

END SUB

 

#WRITE A PROGRAM TO CALCULATE THE SUM OF ODD DIGITS OF A NUMBER.

DECLARE SUB SUM(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL SUM(N)

END

SUB SUM(N)

WHILE N<>0

R=N MOD 10

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

N=N\10

WEND

PRINT “SUM OF ODD DIGITS OF A NUMBER=”;S

END SUB

 

#WRITE A PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS ALPHABET OR NUMBER.

DECLARE SUB CHECK(N$)

CLS

INPUT “ENTER ANY CHARACTER”;N$

CALL CHECK(N$)

END

SUB CHECK(N$)

IF ASC(N$)>=48 AND ASC(N$)<=57 THEN

PRINT “THE CHARACTER IS NUMBER”

ELSE IF(ASC(N$)>=65 AND ASC(N$)<=90) OR (ASC(N$)>=97 AND ASC(N$)<=122) THEN

PRINT “THE CHARACTER IS ALPHABET”

ELSE

PRINT “NEITHER NUMBER NOR ALPHABET”

END IF

END SUB

 

#WRITE A PROGRAM TO FIND THE FACTORS OF A GIVEN NUMBER.

DECLARE SUB FACTOR(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL FACTOR(N)

END

SUB FACTOR(N)

FOR I=1 TO N

IF N MOD I=0 THEN

PRINT I

END IF

NEXT I

END SUB

 

#WRITE A PROGRAM TO FIND THE FACTORIAL OF A GIVEN NUMBER. [5!=5*4*3*2*1]

DECLARE SUB FACTORIAL(N)

CLS

INPUT “ENTER ANY NUMBER”;N

CALL FACTORIAL(N)

END

SUB FACTORIAL(N)

F=1

FOR I=1 TO N

F=F*I

NEXT I

PRINT “FACTORIAL OF”;N;”IS”;F

END SUB

 

#WRITE A PROGRAM TO COUNT THE TOTAL NUMBER OF “S” PRESENT IN A STRING.

DECLARE SUB COUNT(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL COUNT(A$)

END

SUB COUNT(A$)

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “S”

S=S+1

END SELECT

NEXT I

PRINT “TOTAL NUMBER OF S IN A STRING=”;S

END SUB

 

#WRITE A PROGRAM TO COUNT ANY CHARACTER PRESENT IN A STRING USING SUB PROCEDURE.

DECLARE SUB COUNT(A$,B$)

CLS

INPUT “ENTER ANY STRING”;A$

INPUT “ENTER CHARACTER YOU WANT TO COUNT”;B$

CALL COUNT(A$,B$)

END

SUB COUNT(A$,B$)

FOR I=1 TO LEN(A$)

C$=MID$(A$,I,1)

D$=UCASE$(C$)

IF B$=D$ THEN C=C+1

NEXT I

PRINT “NUMBER OF”;B$; “IN A GIVEN STRING=”;C

END SUB

 

#WRITE A PROGRAM TO INPUT ANY STRING AND COUNT THE TOTAL NUMBER OF VOWELS, CONSONANTS, AND WORDS FROM THE STRING.

DECLARE SUB COUNT(A$)

CLS

INPUT “ENTER ANY STRING”;A$

CALL COUNT(A$)

END

SUB COUNT(A$)

W=1

FOR I=1 TO LEN(A$)

B$=MID$(A$,I,1)

C$=UCASE$(B$)

SELECT CASE C$

CASE “A”, “E”, “I”, “O”, “U”

V=V+1

CASE “ “

W=W+1

CASE ELSE

C=C+1

END SELECT

NEXT I

PRINT “TOTAL NUMBER OF VOWELS=”;V

PRINT “TOTAL NUMBER OF CONSONANTS=”;C

PRINT “TOTAL NUMBER OF WORDS=”;W

END SUB


Sujit Prasad Kushwaha

A Dedicated Blogger Sharing Insights and Making a Difference.

Post a Comment

The comment section is your chance to make your mark. Don't hold back - add to the discussion and let your personality shine through!

Previous Post Next Post