Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zadanie 3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "conio.h"
- #include <iostream>
- using namespace std;
- class doskonala
- {
- private:
- int dzielenie(int l, int p)
- {
- if(l%p==0)
- return 0;
- else
- return 1;
- }
- int sprawdzam(int l)
- {
- int suma=0;
- for(int i=1; i<l; i++)
- {
- if(dzielenie(l,i)==0)
- suma+=i;
- }
- if(suma==l) return 0; // l jest zajebista
- else
- return 1; // l nie jest doskonala
- }
- public:
- void pierwsza_doskonala()
- {
- int k=1;
- while(1)
- {
- if (sprawdzam(k)==0)
- {
- cout << "Pierwza doskonala: " << k;
- break;
- }
- else
- {
- k++;
- }
- }
- }
- long int szukaj(int d)
- {
- d++;
- while(1)
- {
- if (sprawdzam(d)==0)
- {
- cout << "znalazlem: " << d;
- break;
- }
- else
- {
- d++;
- }
- }
- return d;
- }
- void znajdz_ile_mi_sie_podoba(int n)
- {
- long int x;
- x=1;
- for(int i=0; i<n; i++)
- x=szukaj(x);
- }
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- doskonala a;
- a.znajdz_ile_mi_sie_podoba(5);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement