- 1

# Who can help me I'm beginning

Write a C program that determines whether a number is prime https://code.sololearn.com/cBu0aAuK3q06/?ref=app https://code.sololearn.com/cVI27Yc04h5r/?ref=app https://code.sololearn.com/cX75kB5nBjrs/?ref=app https://code.sololearn.com/cDhO3jxo3pKa/?ref=app https://code.sololearn.com/c48K3iFAZn00/?ref=app

7 Answers

+ 2

Thanks

+ 3

Please DO NOT link code that is not related to your question.
What have you tried so far? Can you please link your code so we can have a look at it?
You can find example codes only.
https://www.programiz.com/c-programming/examples/prime-number

+ 2

Yes, that's what you have already told us.
Have a look at the 2nd paragraph: I asked some questions there.

0

I'm new here

0

#include <stdio.h>
#include <math.h>
int main() {
int n,i;
printf("enter any number");
scanf("%d/2",&n);
for(i=2;i<=1;i++)
{
printf("not prime number: ");
}
return 0;
}

0

#include <stdio.h>
int isPrime (int n) ;
int main() {
int n;
scanf("%d/2",&n);
if(isPrime(n)==1)
printf("prime number");
else
printf("Not Prime number");
return 0;
}
int isPrime(int n){
for(int i=3;i<n;i++)
if(n%2==0)return 0;
return (n>1?1:0);
}

0

#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
// 0 and 1 are not prime numbers
// change flag to 1 for non-prime number
if (n == 0 || n == 1)
flag = 1;
for (i = 2; i <= n / 2; ++i) {
// if n is divisible by i, then n is not prime
// change flag to 1 for non-prime number
if (n % i == 0) {
flag = 1;
break;
}
}
// flag is 0 for prime numbers
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
return 0;
}