71: Write a program in C++ to list composite numbers from 1 to an upperbound.
// Write a program in C++ to list composite numbers from 1 to an upperbound. Go to the editor
// Sample Output:
// Input the upperlimit: 25
// The composite numbers are:
// 4 6 8 9 10 12 14 15 16 18 20 21 22 24 25
#include <iostream>
using namespace std;
int main()
{
int limit;
cout << "\nInput an upperlimit: ";
cin >> limit;
cout << "\n**************************************************************\n\n";
int a;
cout << "The composite numbers upto " << limit << " are: \n";
for (int i = 1; i <= limit; i++)
{
a = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0)
{
a++;
}
}
if (a > 2)
{
cout << i << ' ';
}
}
cout << "\n\n**************************************************************\n\n";
return 0;
}
Comments
Post a Comment