Search
 
SCRIPT & CODE EXAMPLE
 

C

prime number program in c

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;
}
Comment

prime numbers c

#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);
    
}
Comment

Prime Number Check Program in C

#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:
Comment

prime number in c

#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);
        }
    }
}
Comment

prime number c program

int isPrime(int n) {
  for (int i = 2; i < n; i++) if (n % i == 0) return 0; 
  return 1;
}
Comment

prime number in c

#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;  
 }    
Comment

PREVIOUS NEXT
Code Example
C :: binary tree in c search 
C :: convert int to char in c 
C :: c program to find the frequency of all characters in a string 
C :: c read n bytes code 
C :: The fscanf and fprintf functions 
C :: C program to check whether character is lowercase or not using ASCII values 
C :: Example of Implementation of a pointer to an array in C: 
C :: How to convert string to int without using library functions in c 
C :: c code to grade marks 
C :: How to pass a struct value to a pthread in c? 
C :: int to double c 
C :: clear screen in c 
C :: read file c 
C :: set the nth bit 
C :: pop and push shows black screen which needs to be pressed back flutter 
C :: c linked list 
C :: pyinstaller hidden import tensorflow not found 
C :: c str add int 
C :: C Program to Check Whether Character is Lowercase or Not using islower function 
C :: working outside of application context 
C :: how to make two arrays equal in c 
C :: boolean operators in c 
C :: create syscall 
C :: swap using third variable 
C :: cocktail sort in c 
C :: main prototype 
C :: print integer to stdout using write or putchar? 
C :: VLOOKUP CHECK #N/A 
C :: Integer Xor swap 
C :: gnuplot rectangle border color 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =