Write a C program to check whether given number is prime or not by performing following steps:
Compile and test the program on CS Linux systems
#include <stdio.h> int is_prime(int n) { int i; for (i = 2; i < n; ++i) { if (n % i == 0) { return 0; } } return n > 1; } int main() { int given_number; printf("Enter a number: "); scanf("%d", &given_number); if (is_prime(given_number)) { printf("%d is a prime number\n", given_number); } else { printf("%d is not a prime number\n", given_number); } return 0; }
Get Answers For Free
Most questions answered within 1 hours.