Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /*
  2. ZADANIE 2
  3. --------------------------------------------------------------------------------
  4. O(1)
  5.  
  6. #include <stdio.h>
  7. #include <iostream>
  8. using namespace std;
  9. int main()
  10. {
  11. int x, s;
  12. cin >> x;
  13. s = ((1+x)/2)*x;
  14. cout<<s<<endl;
  15. return 0;
  16. }
  17. --------------------------------------------------------------------------------
  18. O(n)
  19.  
  20. #include <stdio.h>
  21. #include <iostream>
  22. using namespace std;
  23. int main()
  24. {
  25. int x,suma = 0;
  26. cin>>x;
  27. for (int i=1; i<=x; i++)
  28. {
  29. suma+=i;
  30. }
  31. cout<<suma<<endl;
  32. }
  33. --------------------------------------------------------------------------------
  34. O(n^2)
  35.  
  36. #include <stdio.h>
  37. #include <iostream>
  38. using namespace std;
  39. int main()
  40. {
  41. int x, suma=0;
  42. cin>>x;
  43. for(int i = 1; i<=x; i++)
  44. {
  45. for(int j=1;j<=i;j++)
  46. {
  47. suma+=1;
  48. }
  49. }
  50. cout<<suma<<endl;
  51. }
  52. --------------------------------------------------------------------------------
  53. ZADANIE 3
  54.  
  55. a) zlozonosc O(n) - iteracyjnie
  56.  
  57. #include <stdio.h>
  58. #include <iostream>
  59. using namespace std;
  60. int main()
  61. {
  62. int f0=0, f1=1, fn=0,n;
  63. cin>>n;
  64. for (int i=1;i<n;i++)
  65. {
  66. fn = f1 + f0;
  67. f0=f1;
  68. f1 = fn;
  69. }
  70. cout<<fn<<endl;
  71. }
  72.  
  73. b)
  74. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement