Write a C program to check whether a number is a Strong Number or not using the Virtual base Class in Object Oriented Programming(OOP).
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 45 46 47 48 49 50 51 52 53 54 55 56 | #include<iostream> using namespace std; class Grand_FatherT4Tutorials { public : int ip; }; class p1:virtual public Grand_FatherT4Tutorials { public : int sum; }; class p2:virtual public Grand_FatherT4Tutorials { public : int save; }; class derived:public p1,public p2 { protected : int fact,num; public : s_num(); }; derived::s_num() { sum=0; cout<<"Enter number to check: "; cin>>ip; save=ip; while(ip) { num=ip%10; fact = 1; for(int i=num;i>0;i--) { fact=fact*i; } sum+=fact; ip/=10; } if(sum==save) { cout<<save<<" is a Strong Number"; } else { cout<<save<<" is not a Strong Number"; } } int main() { derived a; a.s_num(); } |
Some FAQ
1 is a strong number or not? 1 is a strong number.
2 is a strong number or not? 2 is a strong number.
3 is a strong number or not? 3 is not a strong number.
4 is a strong number or not? 4 is not a strong number.
5 is a strong number or not? 5 is not a strong number.
6 is a strong number or not? 6 is not a strong number.
7 is a strong number or not? 7 is not a strong number.
8 is a strong number or not? 8 is not a strong number.
9 is a strong number or not? 9 is not a strong number.