- #1
chaoseverlasting
- 1,050
- 3
I was writing a program to find if a given number is prime or not. I can't figure out what the error is.
Code:
/* To check if a number is prime*/
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float a;
int p,i,f=0;
p=sqrt(a);
if(a % 2==0) // Shows an error: Cant convert float and int types to binary %
cout<<"\nNot a prime";
else
for(i=3;i<=p;i+=2)
if(a%i==0) //Same error here
break;
if(i==p||i==(p+1))
cout<<"\nThe number is a prime";
else
cout<<"\nThe number is not a prime";
return 0;
}