“Check in C Prime C” Kode Jawaban

Check in C Prime C

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;
	}
}
Nasty Narwhal

Program pemeriksaan bilangan prima di 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:
Repulsive Rattlesnake

Jawaban yang mirip dengan “Check in C Prime C”

Pertanyaan yang mirip dengan “Check in C Prime C”

Lebih banyak jawaban terkait untuk “Check in C Prime C” di C

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya