Sie sind auf Seite 1von 3

Factorial of a number using Friend function

Class A { Private: Int n; Friend void fact(A); Void print (); Public: A(int p) { n=p; } }; Void A::print() { long f=1; For (Int i=1;i<=n;i++) F*=I; Cout << factorial <<f; }

Void fact(A a) { a.print(); } Void main() { Int n; Cout<< enter numbr ; Cin>>n; A c(n); Fact (c); getch();
}

Friend function
Class sample{ Int a Int b; Public: Void setvalue() { a=2,b=6;} Friend float mean(sample s); }; Float mean(sample s) { Return float (s.a +s.b)/2.0; } Int main() { Sample x; x.Setvalue(); Cout<< mean value <<mean(X); Return 0; }

Das könnte Ihnen auch gefallen