#include<stdio.h>
int main() {
int n;
int a=0;
printf(“Enter a number to check whether it is prime or not”);
scanf("%d",n);
for(int i=2;i<n;i++)
{
if(n%i==0)
{a=a+1;}
}
if(a>0)
printf("%d is not a prime no.",n);
else
printf("%d is a prime no.",n);
}
according to me ,this program is correct.
Can you please give the link to the question?
scanf("%d",n);///mistake in taking input update it to scanf("%d",&n);
2 Likes
You Can Speed Up The Solution By Iterating Till Square root of n (i.e your number)