Prime Composite

#include<iostream>
using namespace std;

int main() {
	int i, no;

	/* Declear boolean type variable in C++ */
	bool flag = true;

	/* 'endl' insert linefeed like '\n' */
	cout << "Check the given number is Prime or Composite" << endl;
	cout << "Enter a number:" << endl;
	cin >> no;
	i = no / 2;
	
	/* Loop the process using "while loop" */
	while(i >= 2) {
		if(no % i == 0) {
			flag = false;
			cout << "It's a Composite number!" << endl;
			break;
		}
		i = i - 1;
	}

	if(flag)
		cout << "It's a Prime Number!" << endl;
	return 0;
}


/****** Output ******/

Check the given number is Prime or Composite


Enter a number:


23


It's a Prime Number!






-------------------------------






Check the given number is Prime or Composite


Enter a number:


99


It's a Composite Number!

Recommended for you