Advertisement
Guest User

Rafał Olejniczak zd 1

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, m, i, j;
  8. int dzie = 0, sto = 0, tys = 0, tyss = 0, tysss = 0, mil = 0;
  9. cout << "Podaj minimum: ";
  10. cin >> n;
  11. cout << "Podaj maximum: ";
  12. cin >> m;
  13.  
  14. int tab[m+1];
  15.  
  16. for (i = 0; i <= m+1; i++)
  17. {
  18. tab[i] = i;
  19. }
  20. for (i = 2; i*i <= m+1; i++)
  21. {
  22. if (tab[i] != 0)
  23. {
  24. for (j = 2*i; j <= m; j+= i)
  25. {
  26. tab[j] = 0;
  27. }
  28. }
  29. }
  30.  
  31. cout << "Liczby pierwsze od ," << n << "do" << m << " to:" << endl;
  32. for (i = n; i <= m; i++)
  33. {
  34. if (tab[i] != 0)
  35. {
  36. cout << tab[i] << " ";
  37. cout << endl;
  38. if ((i > 9) && (i < 100))
  39. {
  40. dzie++;
  41. }
  42. if ((i > 99) && (i < 1000))
  43. {
  44. sto++;
  45. }
  46. if ((i > 999) && (i < 10000))
  47. {
  48. tys++;
  49. }
  50. if ((i > 9999) && (i < 100000))
  51. {
  52. tyss++;
  53. }
  54. if ((i > 99999) && (i < 1000000))
  55. {
  56. tysss++;
  57. }
  58. if ((i > 999999) && (i < 10000000))
  59. {
  60. mil++;
  61. }
  62. }
  63. }
  64.  
  65. cout << "10-100 = " << dzie << endl << "100-1000 = " << sto << endl << "1000-10000 = " << tys << endl << "10000-100000 = " << tyss << endl << "100000-1000000 = " << tysss << endl << "1000000-10000000 = " << mil << endl;
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement