Programming in "C‟ | Write a „C‟ program to find whether the entered number is prime or not.

 (Note: Any other correct logic shall be considered).

 #include<stdio.h>

#include<conio.h>

void main() {

int num, flag = 0, i;

clrscr();

printf("Enter the number");

scanf("%d",&num);

for(i = 2;i<num;i++) {

flag = 0;

if(num%i==0) {

flag=0;

break;

} else {

flag =1;

}

}

if(flag==1) {

printf("The number is prime");

} else {

printf("The number is not prime");

}

getch();

Post a Comment

0 Comments