bool isPrime(int x = 0)
{
/* Without extra 'count' variable */
//! corner case: 0 and 1 aren't prime numbers
if (x == 0 || x == 1)
return 0;
for (int i = 2; i <= x / 2; i++)
{
if (x > 2 && x % i == 0)
return 0;
}
return 1;
}
#include<stdio.h>
void main()
{
int num;
int prime = 1;
printf("Enter a number = ");
scanf("%d",&num);
for(int i = 2; i < num; i++)
{
if(num % i == 0)
{
prime = 0;
break;
}
}
if(prime == 1 && num>0 && num !=1)
printf("%d is a prime number.", num);
else
printf("%d isn't a prime number.", num);
}
#include<stdio.h>
void main(){
int num, i;
int cp = 1;
printf("Enter a number = ");
scanf("%d",&num);
if(num > 0){
for(i = 2; i < num; i++){
if(num % i == 0){
cp = 0;
}
}
if(cp == 1){
printf("%d is a prime number.", num);
}
else{
printf("%d isn't a prime number.", num);
}
}
}
int isPrime(int n) {
for (int i = 2; i < n; i++) if (n % i == 0) return 0;
return 1;
}
#include<stdio.h>
int main(){
int n,i,m=0,flag=0;
printf("Enter the number to check prime:");
scanf("%d",&n);
m=n/2;
for(i=2;i<=m;i++)
{
if(n%i==0)
{
printf("Number is not prime");
flag=1;
break;
}
}
if(flag==0)
printf("Number is prime");
return 0;
}
Code Example |
---|
C :: malloc int array c |
C :: first program in c |
C :: Prime Number Check Program in C |
C :: arduino digital read |
C :: printf c float |
C :: print ascii value in c |
C :: armstrong number using function in c |
C :: que es % en c |
C :: A binary tree whose every node has either zero or two children is called |
C :: what is strikethrough in markdown |
C :: check if the c code is a palindrome |
C :: armstrong number in c |
C :: how to checkout branch from commit id |
C :: take long long input in c |
C :: read string with space c |
C :: add char to char array c |
C :: C Program to Find Largest and Smallest Number among N |
C :: c substring |
C :: try and catch in rust |
C :: inputting an array in c |
C :: volatile keyword in c |
C :: c typedef |
C :: variables in c |
C :: how to empty array in c |
C :: terraform fargate cpu |
C :: argparse allow line break |
C :: c list |
C :: c file struct |
C :: logical operators in c |
C :: what is clrsce in C |