write a programe to find the factorial of given number
using recursion

Answer Posted / jessie

import util.java.Scanner
class factorial
{
public static void main(string arge[])
{
Scanner s=new Scanner(System.in);
int n=new int();
n=s.nextInt();
fact(n);
fact(int n)
{
if(n==1)
return 1;
else
return (n*fact(n-1));
}
System.out.println("the factorial of number is "+n);
}
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you have any idea how to compare array with pointer in c?

615


What are the advantages of using new operator as compared to the function malloc ()?

764


What is typedef?

685


What is memory leak in c?

641


What is double pointer?

565






What is bin sh c?

590


What is the scope of static variable in c?

543


What is the time and space complexities of merge sort and when is it preferred over quick sort?

682


What is getche() function?

620


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

656


What is the use of gets and puts?

612


Do pointers store the address of value or the actual value of a variable?

618


Why double pointer is used in c?

573


Why can't I perform arithmetic on a void* pointer?

645


Explain what is the benefit of using an enum rather than a #define constant?

734