Site icon T4Tutorials.com

C++ sum of all integer divisible by a number with friend function

Write a C++ program to find the number and sum of all integer between 100 and 200 which are divisible by 9 with friend function.

//Write a program to find the number and Sum of all integer between 100 and 200 which are divisible by 9.

//friend function

#include<iostream>
using namespace  std;
class number
{
	private:
		int i,T4Tutorials_T4Tutorials_Sum=0;
		public:
		number()
				{
					cout<<"numbers that are divisible by 9 between 100 and 200\n";
				for(i=101; i<200; i++)
				if(i%9==0)
				{
					cout<<"numbers divisble by 9 is= "<<i<<endl;
					T4Tutorials_Sum=T4Tutorials_Sum+i;
				}
			}
				friend int in(number);
			};
			int in(number b)
			{
					cout<<" Sum of all numbers divisible by 9 is= "<<b.T4Tutorials_Sum<<endl;
		}
int main()
{
	number b;
	in(b);
}

Output
C++ program sum of all integer divisible by a number

Exit mobile version