include.docx

(14 KB) Pobierz

#include <iostream>

#include <cmath>

 

using namespace std;

 

bool isPrimeFast(int n)

{

     bool isPrime=true;

     

     int l = (int)sqrt(n);

    

     for (int i = 2; i <=l; i++)

     {

             if(n%i==0)

             {

                        isPrime=false;

                        break;

             }

     }

    

     return isPrime;

}

 

int sumaCyfr(int p)

{

    int reszta;

    int suma = 0;

   

    while(p!=0)

    {

               reszta = p%10;

               p=p/10; 

               suma=suma+reszta;

    }

   

    return suma;

}

 

int main()

   

    int n;

    int suma;

   

    cout << "Podaj liczbe naturalna wieksza badz rowna 2: ";

    cin  >> n;

 

    suma = sumaCyfr(n);

   

    if(isPrimeFast(suma))

        cout << "TAK" << endl;

    else

         cout << "NIE" << endl;

   

    system("Pause");

    return 0;

}

   

a) F, F, T

b) F, T, F

c) F, F, T

d) F, T, F

e) T, F, F

f) T, F, F

g) T, F, F

 

#include <iostream>

#include <fstream>

#include <sstream>

#include <vector>

#include <cmath>

#include <string>

 

using namespace std;

 

int konwersjaStringNaInt(string s)

{   

    int j;

    istringstream iss(s);

    iss >> j;

    return j;

}

   

 

int main()

{   

    string liniaZPliku;

    ifstream file1("liczby.txt");

    vector<string> liczbyZPliku;

    vector<int> liczbyPoZamianie;

    vector<int> liczbyParzyste;

    vector<int> liczbyDoWypisania;

    int l;

      

    if(file1.is_open())

    {

        while(!file1.eof())

        {

            getline(file1,liniaZPliku);

            liczbyZPliku.push_back(liniaZPliku);

            

        }

        file1.close();

    }

    else

         cout << "Unable to open file";

        

    for(int i = 0; i < liczbyZPliku.size(); i++)

    {

            liczbyPoZamianie.push_back(konwersjaStringNaInt(liczbyZPliku[i]));

    }

   

    for(int i = 0; i < liczbyPoZamianie.size(); i++)

    {

            if(liczbyPoZamianie[i]%2==0)

              liczbyParzyste.push_back(liczbyPoZamianie[i]);

    }

   

    l = liczbyParzyste.size();

   

    int temp;   

      

    for (int j=1; j < l; j++)   

        for(int i =0; i < l-j; i++)

            if (liczbyParzyste[i]>liczbyParzyste[i+1])

            {

               temp = liczbyParzyste[i];

               liczbyParzyste[i]=liczbyParzyste[i+1];

               liczbyParzyste[i+1]=temp;

            }    

           

    for(int i = 0; i < liczbyParzyste.size(); i++)

    {

            cout << i+1 << " " << liczbyParzyste[i] << endl;

    }       

                                                 

    cout << endl;

    system("Pause");

    return 0;

}

 

Zgłoś jeśli naruszono regulamin