Write a function called "isPrime()” that checks if an integer number is prime or not. The function returns integer 1 if the number is prime, or integer 0 if the number is not prime. Write a simple test program in main() to show that the function works properly.in C programming language.
#include <stdio.h> int isPrime(int n); int main() { int n; printf("Enter a number: "); scanf("%d", &n); if (isPrime(n)) { printf("%d is a prime number.\n", n); } else { printf("%d is not a prime number.\n", n); } return 0; } int isPrime(int n) { int i; for (i = 2; i < n; ++i) { if (n % i == 0) { return 0; } } return n > 1; }
Get Answers For Free
Most questions answered within 1 hours.