Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <time.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. int M,N,br=0;
  13. int broj[10000] = {0};
  14. int i,j,temp,naj=0;
  15.  
  16. ofstream out("test3.txt");
  17.  
  18. for (int i = 0; i < 1; i++) {
  19.  
  20. do{
  21. cout<<"Unesi M: ";cin>>M;
  22. cout<<"Unesi N: ";cin>>N;
  23. }while(M<10000 || M>N || N>99999);
  24.  
  25.  
  26. out<<"Prosti brojevi izmedu "<<M<<" i "<<N<<" su: ";
  27. while (M < N) // trazimo proste brojeve izmedu M i N
  28. {
  29.  
  30. int flag = 0;
  31. for(i = 2; i <= M/2; ++i)
  32. {
  33. if(M % i == 0)
  34. {
  35. flag = 1;
  36. break;
  37. }
  38. }
  39. if (flag == 0){
  40. out << M <<endl; // ispis prostog broja
  41.  
  42. broj[br] = M;
  43. br++;
  44. }
  45.  
  46. ++M;
  47. }
  48. }
  49. out.close();
  50.  
  51. for (i = 0; i < 10; i++)
  52. {
  53. for (j = i + 1; j < i+2; j++)
  54. {
  55. if(i==0 )naj = broj[j]-broj[i];
  56. if((broj[j]-broj[i]) > naj) naj = broj[j] - broj[i];
  57. }
  58. }
  59.  
  60. cout<<"Najveca razlika je: "<<naj<<endl;
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement