Wed May 23 2018
Prime Number
C Programming1209 views
File Name: prime-number.c
#include<stdio.h>
int main() {
int i, no, j=0;
printf("Check the given number is Prime or Composite\n");
printf("Enter a number:\n");
scanf("%d", &no);
i = no / 2;
/* Loop the process using "while loop" */
while(i >= 2) {
if(no % i == 0) {
j = 1;
printf("It's a Composite number!\n");
break;
}
i = i - 1;
}
if(j != 1)
printf("It's a Prime Number!\n");
return 0;
}
/* Output */
Check the given number is Prime or Composite
Enter a number:
6
It's a Composite number!
/* ---------------------------------------- */
Check the given number is Prime or Composite
Enter a number:
5
It's a Prime Number!
Author:Geekboots