I am getting wrong answer for the given problem. But it is running properly in cpp.sh http://ift.tt/1ezaDoz
my solution is:-
// Example program
#include <iostream>
using namespace std;
int prime(int a)
{
//cout<<"****check prime****";
//if(a==0){return ;}
int j;
for(j=2;j<=a/2;j++)
{if((a%j)==0)
{//cout<<endl<<"*** ****"<<j<<endl;
return j;}
}
//cout<<endl<<"*** -1 ****"<<endl;
return -1;
}
int main()
{
int t;
cin>>t;
int a[t];
int n;int x=0;
for(int i=0;i<t;i++)
{
cin>>n;
x=prime(n);
if(x==-1){a[i]=-1; }
else{a[i]=0;}
}
for(int i=0;i<t;i++)
{
if(a[i]==-1){cout<<"LUCKY NUMBER"<<endl;}
else{cout<<"sorry"<<endl;}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire