Sum of n number of odd natural numbers with friend class in C++.

Sum of n number of odd natural numbers by using friend class in C++.

If we declare a class friend class T4Tutorials_odd_number as a friend in a class class T4Tutorials_friend_sum then this class friend class T4Tutorials_odd_number can access the private and protected members of the class class T4Tutorials_friend_sum.

Syntax of friend function in C++

class class_name_T4Tutorials

friend class name of the friend class;



Please enter the value to print the odd Number.


The output is.






The sum of the given input is: 25

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.

Leave a Reply

Your email address will not be published. Required fields are marked *