Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <iostream>
- using namespace std;
- int main()
- {
- int counter = 0;
- int n,i,j;
- printf("Enter n value: ");
- scanf("%d", &n);
- int prime[n+1];
- for(i = 1; i <= n; i++)
- {
- prime[i] = i;
- }
- for(i = 2; i*i <= n; i++)
- {
- if(prime[i] != 0)
- {
- for(j = 2*i; j <=n ; j += i)
- prime[j] = 0;
- }
- }
- printf("Prime numbers are: \n");
- for(i=2; i <= n; i++)
- {
- if(prime[i] != 0)
- {
- printf("%d ",i);
- counter++;
- }
- }
- cout << endl << endl <<"Counter: " << counter << endl;
- cout << "Ratio: " << (double)n/(double)counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement