problem while running

this is a program that display prime numbers from 1 to 100. it has problem linking when i run the program, someone please help. thx

#include <iostream>

class Prime
{ public:
int PrimeNo();
int Display();
};// class Prime number

int Prime::PrimeNo()
{ int i,j,count; //variable for counting loop
count=0;
for(i=1; i<101; i++) // i as the number to be determined
{
for(j=1; j< i%2; j++) //j as the divider
{ if(j%i==0)
count++;
}
}
if(count==2)
cout<<i;
else
cout<<'\n';

return count;
};
Last edited on
You do not have main() function. You did not define Display() function.
after i changed, it become no outpout, y is tat so?

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

class Prime
{ public:
void PrimeNo();
};// class Prime number

void Prime::PrimeNo()
{ int i,j,count; //variable for counting loop
count=0;
for(i=1; i<101; i++)
{
for(j=1; j< i; j++)
{ if(j%i==0)
count++;
}
}
if(count==2)
cout<<i<<"is a prime number\n";
else
cout<<'\n';

};

int main()
{
Prime true;
true.PrimeNo();
return 0;

};
1) true is a reserved word. It should not even compile.

2) Your loos are wrong. They calculate how many divisors are there in first 100 numbers combined. Proper identation and usage of code tags would show it to you easily.
Topic archived. No new replies allowed.