source file name: multilevel.cpp
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class A
{
public:
void sumdigit(int n)
{
int d,sum=0;
while(n>0)
{
d=n%10;
sum=sum+d;
n=n/10;
}
cout<<"\n sum of digit: "<<sum;
}
} ;
class B : public A
{
public:
void fact(int n)
{
int f=1;
for(;n>0;n--)
{
f=f*n;
}
cout<<"\n Factorail value is: "<<f;
}
};
class C :public B
{
public:
void prime(int n)
{
int d=2;
while(d<n)
{
if(n%d==0)
{
cout<<"\n given no is not Prime "<<endl;
break;
}
else
d++;
}
if(d==n)
cout<<"\n give no "<<n<<" is Prime " << endl;
}
};
void main()
{
clrscr();
cout<<"Multilevel Inheritance program: ";
C ob;
ob.sumdigit(1255);
ob.fact(7);
ob.prime(13);
getch();
}
output:
0 Comments
Post a Comment