Fandom

Scratchpad

PLE:Unidad3Ejercicio23

215,986pages on
this wiki
Add New Page
Discuss this page0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

/*
Programa:       Unidad3Ejercicio23.cpp
Descripción:    Cuales y cuantos son los numeros primos entre 1..1000
*/
#include <iostream>
using namespace std;
void main ()
{
        int n, i, conPrimos = 0, numDiv;

        for(n = 1; n <= 1000; n++)
        {
                if( n % 2 == 0 && n != 2 || n == 1);
                else
                {
                        for (i = 3; n % i !=0 && i*i <= n ; i+=2);
                        if (i*i > n)
                        {
                                cout << n << '\t';
                                conPrimos++;
                        }
                }
        }

        cout << "\nLa cantidad de primos es = " << conPrimos;

        cin.ignore();
        cin.get();
}

Also on Fandom

Random wikia