+ 1

What is the warning in this code?

This code is about calculating prime number by using function but it has a warning... i don't know what it is https://code.sololearn.com/cI9HS2OAaf97/?ref=app

26th Jan 2022, 5:35 PM
Amateur
5 Answers
+ 3
Fatemeh What if your loop and if block doesn't execute then your function will not return anything which should return because return type is int so you should return 0 after end of for loop
26th Jan 2022, 5:38 PM
AĶ¢J
AĶ¢J - avatar
+ 2
AĶ¢J Thank u so much
26th Jan 2022, 5:48 PM
Amateur
+ 2
Fatemeh Your program will always return true because of (i < n && c == 0) and if(c == 0)
26th Jan 2022, 5:52 PM
AĶ¢J
AĶ¢J - avatar
+ 2
AĶ¢J Yes... you are true
26th Jan 2022, 6:06 PM
Amateur
+ 1
Also the logic is not true. You cannot find prime number in this way. To find a prime number, we have to check if that number is perfectly divisible by any integers between 2 and the root of our number. If it is perfectly divisible even by 1 number , it is not prime. https://code.sololearn.com/cNQa8jPCopGv/?ref=app
27th Jan 2022, 10:26 PM
Yusuf
Yusuf - avatar