Friday 27 January 2017

Pascal Program to Find Factorial of a Any Positive Number

Hey, is been a while today tutorial is on Pascal Program to Find Factorial of  Any given Positive Number, You will be able to Calculate the factorial of a number using the example i have given below.

 I'm sharing this code because it was my examination question on final year of computer Science, Heritage Polytechnic Eket Akwa Ibom State, here in Nigeria.

I have seen this question a lot of time been asked an there is no appropriate answer to it, so i wrote this lines of code in pascal to solve this long time mind troubling question.  

You will learn to calculate the factorial of a number using for loop in this example.

Therefore, This example uses nested for loop function in pascal. this pascal program generates factorial.

The factorial of a positive number n is given by:

factorial of n (n!) = 1*2*3*4....n

Example: Factorial of a Number In Pascal



program FactorialOfAnyNumber;
var
i,a,b,j:integer; {initialize variables}
begin
writeln('Enter Any number:'); { Display message for next action}
readln(j); {accept input from keyboard}

for i := 1 to j do {loop through value store in j variable}
begin
a:=i*a; {incremnet as it loop an store result in a variable}

for a:=1 to a do { loop result}
begin
  b:=a; {store total answer to to variable b}
end; {end for loop statement}
end; {end for loop statement}

  writeln('The factorial of ',j,' is = ',b); {Dispay result on screen}
readln(); {delay message}
end. { end program, terminate }

This program takes a positive integer from the user and computes factorial using for loop.

Previous Post
Next Post

post written by:

3 comments:

  1. Enter your comment...Thanks for this tutorial, i was looking for this, all over the net, u saved my googling. Keep the good work

    ReplyDelete
  2. hello, this is naina from Tanzania. I really like your post and every time I am following your posts. please continue this it's a great job.
    Social Media Marketing Services India

    ReplyDelete
  3. Hi, I am Pallavi thank you for this informative post.Fantastic article to go through,I would appreciate the writer's
    123movies

    ReplyDelete

Hit me with a comment!