Search This Blog

UI/UX Design | Web Development | Mobile Application Development

Whether you need UI/ UX design, web development services, or mobile app development services, Qaabil Digitals will be more than happy to help you. We work with top software developers, designers, and project managers. We tailor our services to suit your exact needs. We closely look at your company, listen to your story, and bring about the best ideas and solutions that can help you drive solid results. We don’t just produce work that works. We produce work that matters. Get a quote now Or Talk to us

Tuesday 5 July 2011

Write a program to print factorial of any number


import java.util.*;
class factorial
{
public static void main (String arg[])
{
Scanner in = new Scanner (System.in);

int a,b=1;
System.out.print ("\n\t Enter the number = ");
a=in.nextInt();

while (a>0)
{
b*=a;
--a;
}

System.out.println ("\n\t Factorial = "+b);

}
}

Note:
     First of all computer will check the condition of while loop. If it is true then it will
 multiply b by a. After that it will decrease the value of a by 1 and repeat the same task. This
 will continue until a=0. When a=0 the loop will be broken and the next statement to it will
be executed.

1 comment:

  1. i have a question how we will take different numbers and then it will print the factorial of all the numbers that are entered from the user

    ReplyDelete

Share