- Get link
- X
- Other Apps
CLS
INPUT "Enter first number: "; A
INPUT "Enter second number: "; B
INPUT "Enter third number: "; C
IF A > B AND A > C THEN
PRINT "Greatest number = "; A
ELSEIF B > A AND B > C THEN
PRINT "Greatest number = "; B
ELSE
PRINT "Greatest number = "; C
END IF
END
Explanation
The program takes three numbers and compares them using IF–ELSEIF–ELSE to find the largest number.
b) Program to find factorial of a number
Program
CLS
INPUT "Enter a number: "; N
F = 1
FOR I = 1 TO N
F = F * I
NEXT I
PRINT "Factorial = "; F
END
Explanation
Factorial is calculated by multiplying numbers from 1 to the given number using FOR loop.
c) Display Name, Age, Address, Phone using FOR...NEXT
Program
CLS
FOR I = 1 TO 1
PRINT "Name: Ram"
PRINT "Age: 14"
PRINT "Address: Kathmandu"
PRINT "Phone: 9812345678"
NEXT I
END
Explanation
FOR…NEXT loop is used to print personal details.
d) Series and Patterns
a. 1, 2, 3 … up to 100
CLS
FOR I = 1 TO 100
PRINT I;
NEXT I
END
b. 1,3,5, ...... up to 100
CLS
N = 1
FOR I = 1 TO 100
PRINT N;
N = N + 2
NEXT I
END
c.
1
12
123
1234
12345
CLS
FOR I = 1 TO 5
FOR J = 1 TO I
PRINT J;
NEXT J
PRINT
NEXT I
END
d.
*
**
***
****
*****
CLS
FOR I = 1 TO 5
FOR J = 1 TO I
PRINT "*";
NEXT J
PRINT
NEXT I
END
- Get link
- X
- Other Apps
Comments
Post a Comment