Write a program in C++ to find the number and sum of all integer between 100 and 200 which are divisible by 9.
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 42 43 44 |
//Write a program to find the number and sum of all integer between 100 and 200 which are divisible by 9. //virtual class #include<iostream> using namespace std; class number { public: int i; }; class number2:public virtual number { public: int sum; }; class number3:public virtual number { public: int n; }; class final:public number2 , public number3 { public: int show_num() { cout<<"enter a first number of your loop to start loop :"<<endl; cin>>n; sum=0; for(i=n; i<200; i++) if(i%9==0) { cout<<"numbers divisble by 9 is= "<<i<<endl; sum=sum+i; } cout<<"sum of all numbers divisible by 9 is= "<<sum<<endl; } }; int main() { final d; d.show_num(); } |