include

#include <iostream>

using namespace std;

int czyWesola(int n)

{

int sumaKw;

while(true)

{

sumaKw = 0;

while(n>=10)

{

sumaKw = sumaKw + (n - n/10*10)*(n - n/10*10);

n = n/10;

}

sumaKw = sumaKw + n*n;

n = sumaKw;

if(sumaKw==1)

return 1;

if(sumaKw==4)

return 4;

}

}

int main()

{

int n;

cout << "Podaj n = ";

cin >> n;

cout << czyWesola(n) << endl;

system("pause");

return 0;

}

#include <iostream>

#include <sstream>

#include <fstream>

#include <string>

using namespace std;

int czyWesola(int n)

{

int sumaKw;

while(true)

{

sumaKw = 0;

while(n>=10)

{

sumaKw = sumaKw + (n - n/10*10)*(n - n/10*10);

n = n/10;

}

sumaKw = sumaKw + n*n;

n = sumaKw;

if(sumaKw==1)

return 1;

if(sumaKw==4)

return 4;

}

}

int konwersjaStringToInt(string s)

{

int j;

istringstream iss(s);

iss >> j;

return j;

}

int main()

{

string line;

ifstream myfile("wes_dane.txt");

ofstream myfile1("plik.txt");

if(myfile.is_open())

{

while(!myfile.eof())

{

getline(myfile,line);

myfile1 << line << " " << czyWesola(konwersjaStringToInt(line)) << endl;

}

}

else

cout << "Nie mozna odczytac pliku!" << endl;

system("pause");

return 0;

}

d)

ile 1 ile 2 ile 3 ile 4 ile 5 ile 6

17 53 59 45 19 7

e)

pyt 1 pyt 2 pyt 3 pyt 4 pyt 5 pyt 6 pyt 7 pyt 8 pyt 9 pyt 10

dobra 177 167 155 149 144 142 142 180 111 100

zła 21 23 34 40 43 45 38 9 43 39

brak 2 10 11 11 13 13 20 11 46 61

729 4

559 4

120 4

301 1

940 1

713 4

241 4

513 4

517 4

186 4

271 4

390 4

49 1

31 1

880 4

924 4

490 1

809 4

777 4

428 4

840 4

416 4

279 4

66 4

568 4

752 4

426 4

470 4

44 1

824 4

289 4

546 4

678 4

1 1

93 4

102 4

748 1

328 4

315 4

725 4

107 4

256 4

877 4

739 1

623 1

291 1

501 4

576 4

453 4

950 4

729

559

120

301

940

713

241

513

517

186

271

390

49

31

880

924

490

809

777

428

840

416

279

66

568

752

426

470

44

824

289

546

678

1

93

102

748

328

315

725

107

256

877

739

623

291

501

576

453

950

[Project]

FileName=zad2.dev

Name=Project1

UnitCount=1

Type=1

Ver=1

ObjFiles=

Includes=

Libs=

PrivateResource=

ResourceIncludes=

MakeIncludes=

Compiler=

CppCompiler=

Linker=

IsCpp=1

Icon=

ExeOutput=

ObjectOutput=

OverrideOutput=0

OverrideOutputName=

HostApplication=

Folders=

CommandLine=

UseCustomMakefile=0

CustomMakefile=

IncludeVersionInfo=0

SupportXPThemes=0

CompilerSet=0

CompilerSettings=

[Unit1]

FileName=zad2c.cpp

CompileCpp=1

Folder=

Compile=1

Link=1

Priority=1000

OverrideBuildCmd=0

BuildCmd=

[VersionInfo]

Major=0

Minor=1

Release=1

Build=1

LanguageID=1033

CharsetID=1252

CompanyName=

FileVersion=

FileDescription=Developed using the Dev-C++ IDE

InternalName=

LegalCopyright=

LegalTrademarks=

OriginalFilename=

ProductName=

ProductVersion=

AutoIncBuildNr=0

#include <iostream>

using namespace std;

bool czyPierwsza(int n)

{

int i=2;

while(i*i<=n)

if (n%i==0)

return false;

else

i++;

return true;

}

int main()

{

int n,ln=0;

cout << "Podaj n: ";

cin >> n;

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

if ((czyPierwsza(i))&&((n%i)==0))

{

cout << i << " ";

ln++;

}

cout << endl << "Liczba n ma " << ln << " dzielnikow pierwszych. " << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

#include <iostream>

using namespace std;

int main()

{

int i,n;

bool b=true;

int a[100];

cout << "Podaj n: ";

cin >> n;

for(int i=0;i<n;i++)

cin >> a[i];

for(int i=0;i<n-1;i++)

if (a[i] < a[i+1])

{

b=false;

break;

}

if (b)

cout << "Ciag jest schodami do dolu. " << endl;

else

cout << "Ciag nie jest schodami do dolu. " << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

#include <iostream>

using namespace std;

int main()

{

int a[100];

int k=0,j=0,n;

cout << "Podaj n: ";

cin >> n;

for(int i=1;i<=n;i++)

cin >> a[i];

cout << endl;

for(int i=1;i<=n;i++)

cout << a[i] << " ";

cout << endl;

for (int i=1;i<=n-1;i++)

if (a[i] >= a[i+1])

j++;

else

{

if (j >= k)

k=j+1;

j=0;

}

if (j >= k)

k=j+1;

cout << "Dlugosc najdluzszych schodow do dolu: " << k << endl;

system("PAUSE");

return EXIT_SUCCESS;

}


Wyszukiwarka