Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. bool prost(int x) {
  4.  
  5. for (int j = 2; j < x; j++) {
  6. if (x%j == 0) {
  7. return false;
  8. }
  9. }
  10. return true;
  11. }
  12. int main() {
  13.  
  14.  
  15. // napišite program u kojem ćete omogućiti unos dva prirodna broja manja od 500 koji predstavljaju granice intervala
  16.  
  17. int x = 0;
  18. int y = 0;
  19. int suma = 1;
  20.  
  21. do {
  22. cout << "Molimo unesite dva broja manja od 500" << endl;
  23. cin >> x;
  24. cin >> y;
  25. } while (x >= 500 || y >= 500);
  26.  
  27. //te pronaći i ispisati kojom cifrom/znamenkom završava umnožak svih prostih brojeva u zadanom intervalu uključujući granične vrijednosti.
  28.  
  29. for (int i = x; i <= y; i++) {
  30. if (prost(i) == true) {
  31. suma *= i;
  32. }
  33. }
  34. cout << "Suma je" <<suma<< endl;
  35.  
  36.  
  37. system("pause>null");
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement