how to remove the error shown?
"ILLEGAL USE OF FLOATING POINT"
#include<iostream.h>
#include<conio.h>
#include<process.h>
main()
{
double a;
cout<<"Enter a number\n";
cin>>a;
for(int j=2;j<=a;j++)
if(a%j == 0)
{
cout<<"Its not a prime number\n";
exit(0);
}
开发者_高级运维 else
cout<<"Its a prime number\n";
getch();
return 0;
}
Replace double a
with an integer data type like int
or long
. You cannot do a modulus operation (%
) on floating point numbers (hence the error about illegal use on floating point numbers).
精彩评论