#include
using namespace std;
int main()
{
long long int n;
int i, m=0, flag=0;
cout << "Enter the Number to check Prime: ";
cin >> n;
m=n/2;
for(i = 2; i <= m; i++)
{
if(n % i == 0)
{
cout<<“Number is not Prime.”<<endl;
flag=1;
break;
}
}
if (flag==0)
cout << “Number is Prime.”<<endl;
return 0;
}
Error in code while rumming
@uks.2610
you dont need to print Enter the prime number and you only need to print Prime or Not Prime please read the question carefully for I/O
please refer to this code if something’s unclear
Compiling failed with exitcode 1, compiler output: prog.cpp: In function ‘int main()’: prog.cpp:6:3: error: expected unqualified-id before ‘int’ int i, m=0, flag=0; ^~~ prog.cpp:9:3: error: ‘m’ was not declared in this scope m=n/2; ^ prog.cpp:10:7: error: ‘i’ was not declared in this scope for(i = 2; i <= m; i++) ^ prog.cpp:15:11: error: ‘flag’ was not declared in this scope flag=1; ^~~~ prog.cpp:15:11: note: suggested alternative: ‘float’ flag=1; ^~~~ float prog.cpp:19:7: error: ‘flag’ was not declared in this scope if (flag==0) ^~~~ prog.cpp:19:7: note: suggested alternative: ‘float’ if (flag==0) ^~~~ float
please see itcthis is coming now
have you checked the code provided by me ?
why u have not written iostream
Hello @uks.2610,
Because he has included: #include<bits/stdc++.h>
The <bits/stdc++. h> is a header file. This file includes all standard library. Sometimes in some coding contests, when we have to save time while solving, then using this header file is helpful.
So, this file itself includes iostream headerfile.
Hope, this will help.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.