Advertisements
Advertisements
प्रश्न
Given below is the program with errors in it. Identify the errors. Rewrite the program and predict the output.
import java.util.*;
class ProGram
{
void main()
{
int n=0, tn = 0, p = 0 ; Scanner sc = new Scanner (System.in);
System.out.print("\n Enter total terms (n) :");n = sc.nextInt();
for(tn = n; tn<=1; tn--)
{
p =p*tn;
System.out.print("Factorial of n =" + p );
}
}
}कोड लेखन
Advertisements
उत्तर
import java.util.*;
class ProGram
{
void main()
{
int n=0, tn = 0, p = 1; Scanner sc=new Scanner(System.in);
System.out.print("\n Enter total terms (n):");n=sc.nextInt();
for(tn = n; tn>= 1; tn--)
{
p=p*tn;
}
System.out.print("Factorial of n ="+p);
}
}
Factorial of n
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
