Quyidagi dasturda n soniga jurnaldagi raqamiz kiritilsa dastur natijasini chop eting
#include
using namespace std;
int get(int n){
return n < 2 ? n : get(n-1) + get(n-2);
}
int main(){
int n;
cin >> n;
cout << get(n);
return 0;
}
Ushbu dasturni bajarish jarayonida qanday natija ko'rsatiladi.
#include
using namespace std;
int a[5] = {1,2,3,4,5};
class A{
public:
int display()
{
int s = 0;
for (int i=0; i<5; i++)
s+=a[i];
return s;
}
int summa(int n)
{
int S = 0;
for (int i=1; i<=n; i++)
S+=i;
return S;
}
};
class B:public A{
public:
void result()
{
cout << "Result: " << display() << endl;
cout << " Result: " << summa(100) << endl;
}
};
int main()
{
B x;
x.result();
}
Ushbu dastur qismini bajarish jarayonida qanday natija ko'rsatiladi.
class A{
private:
int a = 25;
int minus()
{
return a -10;
}
public:
void display()
{
cout << minus();
}
};
class B:public A{
public:
};
int main()
{
B x;
x.display();
}
Do'stlaringiz bilan baham: |