A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C++ to list non-prime numbers from 1 to an upperbound
Q:

Write a program in C++ to list non-prime numbers from 1 to an upperbound

0

Write a program in C++ to list non-prime numbers from 1 to an upperbound

Sample Output:

 List non-prime numbers from 1 to an upperbound:                       
----------------------------------------------------                   
 Input the upperlimit: 25                                              
 The non-prime numbers are:                                            
4 6 8 9 10 12 14 15 16 18 20 21 22 24 25

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int ult;
    cout << "\n\n List non-prime numbers from 1 to an upperbound:\n";
    cout << "----------------------------------------------------\n";
    cout << " Input the upperlimit: ";
    cin >> ult;
    cout << " The non-prime numbers are: " << endl;
    for (int num = 2; num <= ult; ++num) 
    {
        int mfactor = (int)sqrt(num);
        for (int fact = 2; fact <= mfactor; ++fact) 
        {
            if (num % fact == 0) 
            {
                cout << num << " ";
                break;
            }
        }
    }
    cout << endl;
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now