Find a no. Is prime or not. Pls fix this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Find a no. Is prime or not. Pls fix this code

Prime no. Finding in C language https://code.sololearn.com/ch15QE4iAE54/?ref=app

12th Nov 2018, 12:26 PM
Rajat Kumar
Rajat Kumar - avatar
1 Answer
+ 17
#include <stdio.h> #include <math.h> main() { int num,i,k; printf("Enter a number :"); scanf("%d",&num); i = 2;k=sqrt (num); while( i<=k){ if(num%i==0&&num!=2){ printf("%d is not a prime number ",num); printf("\n Number % divisible by %d ",num,i); break; } i++; } { if(i==k+1) printf ("\n %d is a prime number",num); } } //have a look at loop , increment of variable [there was main error] + some error in if() statement[logical error] + some error in wrong placed brackets {} //fixed☺
12th Nov 2018, 3:54 PM
Gaurav Agrawal
Gaurav Agrawal - avatar