include

#include <cstdlib>

#include <iostream>

using namespace std;

string fromBtoD(int l)

{

string temp1;

while (l!=0)

{

if (l%2==0)

temp1=temp1+"0";

else

temp1=temp1+"1";

l=l/2;

}

string temp2="";

int dl=temp1.length();

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

temp2=temp2+temp1[dl-i-1];

return temp2;

}

int fromDtoB(string s)

{

int dl=s.length(),suma=0,pot=1;

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

{

suma=suma+((int)s[dl-i-1]-48)*pot;

pot=pot*2;

}

return suma;

}

int main(int argc, char *argv[])

{

int liczbaDzi;

string liczbaDwo="";

cout << "Podaj liczbe dziesietna do zamiany na dwojkowa: " ;

cin >> liczbaDzi ;

cout << fromBtoD(liczbaDzi) << endl;

cout << "Podaj liczbe dwojkowa do zamiany na dziesietna: " ;

cin >> liczbaDwo ;

cout << fromDtoB(liczbaDwo) << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

#include <cstdlib>

#include <iostream>

using namespace std;

int ile1(int l)

{

int i=0;

while (l!=0)

{

if (l%2!=0)

i++;

l=l/2;

}

return i;

}

int main(int argc, char *argv[])

{

int liczbaDzi;

cout << "Podaj liczbe sekund " ;

cin >> liczbaDzi ;

cout << ile1(liczbaDzi) << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

a)

14400 :2|0

7200 :2|0

3600 :2|0

1800 :2|0

900 :2|0

450 :2|0

225 :2|1

112 :2|0

56 :2|0

28 :2|0

14 :2|0

7 :2|1

3 :2|1

1 :2|1

Odp: Na 14 polach.

b)

2^2 + 2^5 + 2^7 + 2^8 + 2^9 + 2^10 + 2^11 + 2^12 =

= 8100 [sekund]

8100/60= 135 [minut]

Odp. Ostatni wykład trwał 135 minut.

#include <cstdlib>

#include <iostream>

using namespace std;

string testLiczby(int n)

{

string temp;

int i=2;

et:

if (i>=n)

temp = "pierwsza";

else if (n%i==0)

temp = "zlozona";

else

{

i++;

goto et;

}

return temp;

}

int main(int argc, char *argv[])

{

int liczba,a,b;

cout<< "Podaj konce przedzialu :";

cin>> a ;

cin>> b ;

for(a;a<=b;a++)

cout<< "Liczba " << a << " jest liczba " << testLiczby(a) << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

#include <cstdlib>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])

{

int n,i;

cout << "Podaj liczbe: ";

cin >> n;

if(n>=2)

{

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

while(n%i==0)

{

cout << i << " ";

n=n/i;

}

cout << endl;

}

else

cout << "Nie da sie" << endl;

system("PAUSE");

return EXIT_SUCCESS;

}

a) F P F

b) F F P

c) F P F

d) F F P

e) P F F

f) P F F

g) F P F

#include <cstdlib>

#include <iostream>

#include <string>

#include <sstream>

#include <fstream>

using namespace std;

int parzystosc(string s)

{

return s.length()%2;

}

bool czyPalindrom(string s)

{

bool temp=true;

int dl = s.length();

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

if (s[i]!=s[dl-i-1])

{

temp=false;

break;

}

return temp;

}

bool sumaKodow220(string s)

{

bool temp=false;

int dl = s.length();

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

if ((int)s[i]+(int)s[i+1]==220)

{

temp=true;

break;

}

return temp;

}

int main(int argc, char *argv[])

{

string line;

int i=0;

ifstream myfile1("hasla.txt");

ofstream myfile2("wynik4b.txt"),myfile3("wynik4c.txt");

if (myfile1.is_open())

{

while (! myfile1.eof() )

{

getline (myfile1,line);

if (parzystosc(line)==0)

i++;

if (czyPalindrom(line))

myfile2 << line << endl;

if (sumaKodow220(line));

myfile3 << line << endl;

}

cout << "Hasel o parzystej dlugosci jest: " << i << endl;

cout << "Hasel o nieparzystej dlugosci jest: " << 200-i << endl;

myfile1.close();

}

else

cout << "Unable to open file" << endl;

system("PAUSE");

return EXIT_SUCCESS;

}


Wyszukiwarka

Podobne podstrony:
include
include
Wykorzystanie błędów w include, DZIAŁ IT, Doc HACK
include
WYK ADY Z C, WYK AD2, #include <stdio
WYK ADY Z C, WYK AD2, #include <stdio
CLAB 10 2009-2010, #include <iostream
include3, budowictwo pcz (h.fresh06), I rok (sem I i sem II), technologia informacyjna, program w c+
include2, Studia, Studia sem III, Uczelnia
include
include, Studia, Studia sem III, Uczelnia
Heathen Ethics and Values An overview of heathen ethics including the Nine Noble Virtues and the Th
include, budowictwo pcz (h.fresh06), I rok (sem I i sem II), technologia informacyjna, program w c++
include2, Studia, Studia sem IV, Uczelnia Sem IV, MN
include34, Studia, Studia sem III, Uczelnia
include
SHSBC (confidential tapes, not included on tape set91)
include

więcej podobnych podstron