Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. cout<<"Wybierz co chcesz sprawdzic. 1-ciag fibonnaciego do podanej liczby 2-czy liczba jest pierwsza" << endl;
  7. int wybor;
  8. int n;
  9. int z=1;
  10. int l1=0;
  11. int l2=1;
  12. int pie;
  13. int fibo;
  14. cin >> wybor;
  15. switch(wybor)
  16. {
  17. case 1:
  18. cout << "ktora liczbe z ciagu fibonnaciego chcesz? ";
  19. cin >> n;
  20.  
  21. for (int i = 0; i <= n; ++i)
  22. {
  23.  
  24. if(i == 1)
  25. {
  26. cout << " " << l1;
  27. continue;
  28. }
  29. if(i == 2)
  30. {
  31. cout << l2 << " ";
  32. continue;
  33. }
  34. fibo = l1 + l2;
  35. l1 = l2;
  36. l2 = fibo;
  37.  
  38.  
  39. }
  40. cout <<fibo<< " ";
  41. break;
  42.  
  43. case 2:
  44. cout<<"Podaj liczbe ktora chcesz sprawdzic?"<<endl;
  45. cin>>n;
  46. cout<<"dzieli sie przez";
  47. for (int i=1; i<=n; i++)
  48. {
  49. if(n%i!=0)
  50. {
  51.  
  52. continue;
  53. }
  54. else
  55. {
  56. z=i;
  57. cout<<" " <<z;
  58. pie++;
  59. }
  60. }
  61. cout<<endl;
  62. if(pie==2)
  63. {
  64. cout<< n << " jest liczba pierwsza!";
  65. }
  66. else
  67. {
  68. cout<< n << " nie jest liczba pierwsza";
  69.  
  70. }
  71. break;
  72. }
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement