Friday 25 July 2014

write a program to read an integer number and evaluate its factorial by recursion.

#include<iostream>
using namespace std;
float factorial(int);

int main()
{
int k;
cout<<"enter the number ";
cin>>k;
cout<<"factorial of"<<k<<"is"<<factorial(k);
}

//function to evaluate the factorial
float factorial(int n)
{
if(n==0)
 return(1);
else
 return(n*factorial(n-1));
}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...