Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ZADANIE 2
- --------------------------------------------------------------------------------
- O(1)
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int x, s;
- cin >> x;
- s = ((1+x)/2)*x;
- cout<<s<<endl;
- return 0;
- }
- --------------------------------------------------------------------------------
- O(n)
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int x,suma = 0;
- cin>>x;
- for (int i=1; i<=x; i++)
- {
- suma+=i;
- }
- cout<<suma<<endl;
- }
- --------------------------------------------------------------------------------
- O(n^2)
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int x, suma=0;
- cin>>x;
- for(int i = 1; i<=x; i++)
- {
- for(int j=1;j<=i;j++)
- {
- suma+=1;
- }
- }
- cout<<suma<<endl;
- }
- --------------------------------------------------------------------------------
- ZADANIE 3
- a) zlozonosc O(n) - iteracyjnie
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int f0=0, f1=1, fn=0,n;
- cin>>n;
- for (int i=1;i<n;i++)
- {
- fn = f1 + f0;
- f0=f1;
- f1 = fn;
- }
- cout<<fn<<endl;
- }
- b)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement