Prime Number

#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!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!