Programming for Problem Solving

GTU Practical 24

24. Write a program to check whether the given number is prime or not.
#include<stdio.h>  ( this applies in the given code )

#include

int main() {
int num, i;
scanf(“%d”, &num);
for (i = 2; i * i <= num; i++) if (num % i == 0) { printf("Not Prime\n"); return 0; } printf("Prime\n"); return 0; }

OUTPUT

Enter a number: 5
5 is a prime number.

GTU STUDY