Posted in

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;

}

Output

Please enter the value to print the odd Number.

5

The output is.

1

3

5

7

9

The sum of the given input is: 25

 CEO @ T4Tutorials.com
I welcome to all of you if you want to discuss about any topic. Researchers, teachers and students are allowed to use the content for non commercial offline purpose. Further, You must use the reference of the website, if you want to use the partial content for research purpose.

Leave a Reply

Contents Copyrights Reserved By T4Tutorials