Write a program in C++ to find the sum of the series using friend function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include<iostream> using namespace std; class T4TUTORIALS { protected : int i,j; int s=0; public : read() { cout<<"enter the value"; int n; cin>>n; int s=0; int t=1,i=1; for(i=1;i<=n;i++) { cout<<" "<<t<<" "; if (i<n) { cout<<"+"; } s=s+t; t=(t*10)+1; } cout<<endl<<"The Sum is :"<<s; } friend int show(T4TUTORIALS); }; int show(T4TUTORIALS a) { cout<<"sum of given input = "<<a.s; } int main() { T4TUTORIALS a; a.read(); show(a); } |