1.

Write a program in QBASIC to accept a number from the user and calculate its factorial .N! = 1*2*3*....*N​

Answer»

Answer:

The GIVEN cσde is written in QBASIC.

CLS

INPUT "Enter a NUMBER: "; A

F = 1

FOR I = 1 TO A

   F = F * I

NEXT I

PRINT "Factorial: "; F

END

Logic:

  • Accept the number, say N.
  • Initialise F = 1
  • Loop through numbers in the RANGE 1 to N.
  • Multiply each number with F.
  • Display the VALUE of F after termination of loop.

See the attachment for output.

•••♪



Discussion

No Comment Found