Advertisement
_Nishat_tasnim

all types of prime number

Dec 8th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int num1, num2;
  8. cout<< "please enter the lowest value and the highest value"<<endl;
  9. cin>>num1>>num2;
  10.  
  11. int k=0,cnt=0,i,j;
  12. int arry[10000];
  13. for(i=num1; i<=num2; i++)
  14. {
  15. for( j=2; j<=i; j++)
  16. {
  17. if(i%j==0)
  18. {
  19. break;
  20. }
  21. }
  22. if(i==j)
  23. {
  24. cnt++;
  25. while(k<cnt)
  26. {
  27. arry[k]=i;
  28. ++k;
  29. //break;
  30. }
  31. }
  32. }
  33. cout<<"The prime numbers are: "<<endl;
  34. for(int i=0; i<cnt; i++)
  35. {
  36. cout<< arry[i]<<'\t';
  37. }
  38. cout<<endl;
  39. cout<<"The total prime number is: "<< cnt<<endl;
  40. int cnt2=0;
  41. for(int i=0,j=i+1; i<cnt-1,j<cnt; i++,j++)
  42. {
  43. if(arry[j]-arry[i]==2)
  44. {
  45. ++cnt2;
  46. }
  47. }
  48. cout<< "There are "<<cnt2<< " pairs of twin primes between "<<num1<<" and "<<num2<<endl;
  49. return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement