.
Home About-us Privacy Policy Contact-us Services

Thursday, October 8, 2015

C++ program to find factorial of a number by using friend function

ad+1

Program

#include<iostream.h>
#include<conio.h>
//void fact(b);
class b
{
int n;
friend void fact(b);
void print();
public:
b(int p)
{
n=p;
}
};
void b::print()
{
long f=1;
for(int i=1;i<=n;i++)
f*=i;
cout<<"factorial is==>"<<f;
}
void fact(b a)
{
a.print();
}
void main()
{
int n;
clrscr();
cout<<"enter the number==>";
cin>>n;
b a(n);
fact(a);
getch();
}


Output:


enter the number==>5
factorial is==>120





0 comments:

Post a Comment

Home About-us Privacy Policy Contact-us Services
Copyright © 2014 All Programs Examples | All Rights Reserved. Blogger Templates Download Blogger Templates