int isPrime(long long number) {
if (number == 0 || number == 1 || (number % 2 == 0 && number > 2)) {
return 0;
}
else {
for (long long i=3; i <= (long long)sqrt(number)+1; i++) {
if (number % i == 0) {
return 0;
}
}
return 1;
}
}
#include <stdio.h>
main() {
int n, i, c = 0;
printf("Enter any number n:");
scanf("%d", &n);
//logic
for (i = 1; i <= n; i++) {
if (n % i == 0) {
c++;
}
}
if (c == 2) {
printf("n is a Prime number");
}
else {
printf("n is not a Prime number");
}
return 0;
}
Program Output:
#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n == 0 || n == 1)
flag = 1;
for (i = 2; i <= n / 2; ++i) {
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;
}
int n=7,i,flag=0;
for(i=2;i<n/2;i++){
if(n%i==0){
flag=1;
break;
}
}
if(flag==0){
printf("Prime number");
}else{
printf("not prime number");
}
Code Example |
---|
C :: how to get user input in c |
C :: %hd c |
C :: types of instruction and there meaning in c |
C :: remove from string c |
C :: print 2d array in c |
C :: how to shutdown system c++ |
C :: for loop c |
C :: cannot get / react router dom |
C :: how to get add to number C |
C :: how to ban websites on mac |
C :: string compare c |
C :: how to sleep in c |
C :: find length of int number in c |
C :: how to open a website in c |
C :: sequelize count multiple associations |
C :: CL/cl.h: No such file or directory |
C :: strcmp c |
C :: extract substring after certain character in flutter |
C :: C Passing Pointers to Functions |
C :: c read file |
C :: functions in c |
C :: c program that replace vowels in a string with char |
C :: stack push |
C :: unsigned char c programming |
C :: function component with props |
C :: absolute value of intel intrinsic |
C :: definir função em c |
C :: c read binary file |
C :: passing pointer to function |
C :: example of header file in c |