Recent Posts

Wednesday 11 June 2014

04:24

Find factorial of any no 

Today we will learn how to find factorial of any no using java . Main thing in every programming language is that you must have your own logic because as we learn new programming languages, we just learn their syntax and some other basic of that language. Our logic remains same .So it is very important for an individual to make logic corresponding to any mathematical  problem.

CODES:

//Copyright @author Harpreet Sandhu
import java.util.*;
 public class fact {
 public static void main(String s[])
 { Scanner c= new Scanner(System.in);
 int n= c.nextInt(); 
int i=1,c=1; 
while(i<=n) { c=c*i; i++; } 
System.out.println("Factorial of "+n+" is = "+c); 
}}


OUTPUT:

e.g  Factorial of 5 is =  120

0 comments:

Post a Comment