Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int num1, num2;
- cout<< "please enter the lowest value and the highest value"<<endl;
- cin>>num1>>num2;
- int k=0,cnt=0,i,j;
- int arry[10000];
- for(i=num1; i<=num2; i++)
- {
- for( j=2; j<=i; j++)
- {
- if(i%j==0)
- {
- break;
- }
- }
- if(i==j)
- {
- cnt++;
- while(k<cnt)
- {
- arry[k]=i;
- ++k;
- //break;
- }
- }
- }
- cout<<"The prime numbers are: "<<endl;
- for(int i=0; i<cnt; i++)
- {
- cout<< arry[i]<<'\t';
- }
- cout<<endl;
- cout<<"The total prime number is: "<< cnt<<endl;
- int cnt2=0;
- for(int i=0,j=i+1; i<cnt-1,j<cnt; i++,j++)
- {
- if(arry[j]-arry[i]==2)
- {
- ++cnt2;
- }
- }
- cout<< "There are "<<cnt2<< " pairs of twin primes between "<<num1<<" and "<<num2<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement