0% found this document useful (0 votes)
42 views4 pages

Computer Programs Using Sub

The document describes 10 computer programs that use sub procedures to perform various tasks involving numbers and strings. The sub procedures include calculating the sum of two numbers, finding the area of a square, determining the greater of two or three numbers, checking if a number is prime, checking if a number is an Armstrong number, checking if a number or word is a palindrome, reversing a number or word, and checking if a number is even or odd. The sub procedures take user input, perform the necessary calculations or comparisons, and output the results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Computer Programs Using Sub

The document describes 10 computer programs that use sub procedures to perform various tasks involving numbers and strings. The sub procedures include calculating the sum of two numbers, finding the area of a square, determining the greater of two or three numbers, checking if a number is prime, checking if a number is an Armstrong number, checking if a number or word is a palindrome, reversing a number or word, and checking if a number is even or odd. The sub procedures take user input, perform the necessary calculations or comparisons, and output the results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Programs using Sub

1. Sum of two Numbers; DECLARE SUB SUM (A, B) CLS INPUT ENTER A NUMBER; A INPUT ENTER A NUMBER; B CALL SUM (A, B) END SUB SUM (A, B) S=A+B PRINT THE SUM OF ; A;AND; B;IS; S END SUB 2. Area of Square; DECLARE SUB AREA (E) CLS INPUT ENTER THE LENGTH; E CALL AREA (E) END SUB AREA (E) A=E*E PRINT THE AREA OF THE SQUARE IS; A END SUB 3. Greater/Smaller Number; DECLARE SUB GRE (A, B) CLS INPUT ENTER A NUMBER; A INPUT ENTER A NUMBER; B CALL GRE (A, B) END SUB GRE (A, B) IF A > B THEN PRINT A;IS GREATER NUMBER ELSE PRINT B;IS THE GREATER NUMBER END SUB 4. Greater Number among 3 Different Numbers; DECLARE SUB GRE (A, B, C) CLS INPUT ENTER A NUMBER; A INPUT ENTER A NUMBER; B INPUT ENTER A NUMBER; C CALL GRE (A, B, C) END

SUB GRE (A, B, C) IF A > B AND A > C THEN PRINT A;IS THE GREATEST ELSEIF B > A AND B > C THEN PRINT B;IS THE GREATEST ELSE PRINT C;IS THE GREATEST END IF END SUB 5. Prime Number; DECLARE SUB PRIME (N) CLS INPUT ENTER A NUMBER; N CALL PRIME (N) END SUB PRIME (N) FOR I = 1 TO N R = N MOD I IF R = 0 THEN C = C + 1 NEXT I IF C = 2 THEN PRINT IT IS PRIME NUMBER ELSE PRINT IT IS COMPOSITE NUMBER END IF END SUB 6. Armstrong Number; DECLARE SUB ARM (N) CLS INPUT ENTER A 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 S = N THEN PRINT N;IS AN ARMSTRONG ELSE PRINT N;IS NOT AN ARMSTRONG END IF END SUB 7. Palindrome; (A)Number; DECLARE SUB PAL (N)

CLS INPUT ENTER A NUMBER; N CALL PAL (N) END SUB PAL (N) A=N WHILE A< > 0 R = A MOD 10 S = S * 10 + R A = A \ 10 WEND IF S=N THEN PRINT N;IS A PALINDROME ELSE PRINT N;IS NOT A PALINDROME END IF END SUB (B)Word; DECLARE SUB PAL (N$) CLS INPUT ENTER A WORD; N$ CALL PAL (N$) END SUB PAL (N$) FOR I = 1 TO LEN (N$) B$ = MID$(N$, I, 1) C$ = B$ + C$ NEXT I IF N$ = C$ THEN PRINT N$;IS PALINDROME WORD ELSE PRINT N$;IS NOT PALINDROME WORD END IF END SUB 8. Reverse Order (A)Number; DELCARE SUB REV (A) CLS INPUT ENTER A 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 S; IS THE REVERSE OF; A END SUB

(B)Word; DECLARE SUB REV (A$) CLS INPUT ENTER A WORD; A$ CALL REV (A$) END SUB REV (A$) FOR I=1 TO LEN (A$) B$ = MID$(A$, I, 1) C$ = B$ + C$ NEXT I PRINT C$; IS THE REVERSE OF;A$ END SUB 10. Even and Odd; DECLARE SUB EVOD (N) CLS INPUT ENTER A NUMBER; N CALL EVOD (N) END SUB EVOD (N) A = N MOD 2 IF A = 0 THEN PRINT N;IS EVEN ELSE PRINT N;IS ODD END IF END SUB

You might also like