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

Latest posts by Prof. Fazal Rehman Shamil (see all)
Posted in C++