C++ Programming

Prime Composite

C plus plus for check the given number is prime or composite number

10/31/2019
0 views
prime-composit.cppCPP
#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!
*/
cppc plus plusprime numbercomposite number

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com