how to remove 1?

F

freeday

#include<iostream.h>
#include<math.h>

void prime(int,int);

void main()
{
int min ,max;
cout<<"min: ";
cin>>min;
cout<<"max: ";
cin>>max;
prime(min,max);
}
void prime(int min,int max)
{
int i,j,k;
for(i=min;i<=max;i+=1)
{

k=int (sqrt(double(i)));
for(j=2;j<=k;j++)
if(i%j==0)
break;
if(j>=k+1 && i!=1)
cout<<' '<<i;
}
cout<<endl;
}
 
K

Karl Heinz Buchegger

[snip code for a prime tester]

I don't understand. What is your question?
remove 1? from where? Why? What is the problem?
 
A

Alf P. Steinbach

* freeday:
#include<iostream.h>

#include<math.h>

void prime(int,int);

void main()

'void main' is not allowed by the standard, use 'int main'.

{
int min ,max;
cout<<"min: ";
cin>>min;
cout<<"max: ";
cin>>max;
prime(min,max);
}
void prime(int min,int max)
{
int i,j,k;
for(i=min;i<=max;i+=1)
{

k=int (sqrt(double(i)));
for(j=2;j<=k;j++)
if(i%j==0)
break;
if(j>=k+1 && i!=1)
cout<<' '<<i;
}
cout<<endl;
}

Indentation is highly misleading; perhaps you therefore think the last
'if' statement is part of the 'j' loop?
 
M

Mike Wahler

Re: how to remove 1?

"One what?"
-Paul Hogan, as 'Mick' in "Crocodile Dundee"


(My reply is phrased humorously, but the question
it asks does apply to your query.)

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top