-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
4,344 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Algorytm Herona lub metoda Newtona-Raphsona: | ||
* – wyszukiwanie pierwiastka metoda przybliżeń | ||
*/ | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
double pierwiastek(double x, double d) { | ||
double a = x; | ||
while (a-(x/a) > d) { | ||
a = (a + (x/a)) / 2; | ||
} | ||
return a; | ||
} | ||
|
||
int main() { | ||
cout << "Program oblicza pierwiastek kwadratowy z liczby rzeczywistej x "; | ||
cout << "z zadaną dokładnością:" << endl; | ||
double x; | ||
double d; | ||
|
||
cout << "Podaj liczbę i dokładność: " << endl; | ||
cin >> x >> d; | ||
cout << "Pierwiastek z x=" << x << " wynosi: " << pierwiastek(x,d) << endl; | ||
cout << "Pierwiastek z x=" << x << " wynosi: " << sqrt(x) << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <iomanip> | ||
|
||
using namespace std; | ||
|
||
inline void stop() { | ||
char b; | ||
cin>>b; | ||
return; | ||
} | ||
// f(n) = 1 dla n {0,1} | ||
// f(n) = f(n-1)+f(n-2) dla n>1 | ||
int fibonacci(int n) { | ||
if (n<2) | ||
return 1; | ||
else | ||
return fibonacci(n-1)+fibonacci(n-2); | ||
} | ||
|
||
int fibonacciit(int n) { | ||
int a = 1; | ||
int b = 1; | ||
int wynik=0; | ||
if (n<2) return 1; | ||
for (int i=2; i<n+1; i++){ | ||
wynik=a+b; | ||
b = a; | ||
a = wynik; | ||
} | ||
return wynik; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int n; | ||
// -------- CIAG FIBONACCIEGO | ||
cout << "Obliczanie wartosci n-tego wyrazu ciagu Fibonacciego: ktory wyraz..." << endl; | ||
cin >> n; | ||
cout << "Wartosc " << n << " wyrazu ciagu: " << fibonacci(n) << endl; | ||
cout << "Ciag Fibonacciego do " << n << " wyrazu: " << endl; | ||
// for (int i=0; i<n+1; i++) { | ||
// cout << "f(" << i << ") = " << setw(4) << fibonacci(i) << " "; | ||
// cout << "iloraz f(" << i << ")/f(" << i-1 << "): " << setw(10) << (float)fibonacci(i)/fibonacci(i-1) << endl; | ||
// } | ||
|
||
for (int i=0; i<n+1; i++) { | ||
cout << "f(" << i << ") = " << setw(4) << fibonacciit(i) << " "; | ||
cout << "iloraz f(" << i << ")/f(" << i-1 << "): " << setw(10) << (float)fibonacciit(i)/fibonacciit(i-1) << endl; | ||
} | ||
cout << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <iostream> // std::cout, std::ios, std::endl | ||
#include <iomanip> // std::setiosflags | ||
#include <cstdio> // printf | ||
#include <math.h> //stała M_PI | ||
|
||
using namespace std; | ||
|
||
/* | ||
* FLAGI fmtflags (typ bitmask): | ||
* Ustawiane selektywne za pomocą cout.setf(fmtflags fmtfl, fmtflags mask): | ||
* [left], right, internal - wyrównanie w polu wyprowadzania (dla liczb - [right]) (adjustfield) | ||
* [dec], oct, hex - system liczbowy, w jakim wypisuje się liczbę (dot. całkowitych) (basefield) | ||
* scientific, fixed - notacja naukowa lub zwykła - dla float/double [bez ustawienia określa się to na podstawie wielkości rzędu liczby] (floatfield) | ||
* | ||
* Ustawiane/anulowane za pomocą cout.setf(fmtflags fmtfl)/cout.unsetf(fmtflags fmtfl); flagi niezależne: | ||
* boolalpha - wartości bool jako true,false | ||
* skipws - powoduje pominięcie (w istreamach) wiodących spacji | ||
* uppercase - litery w liczbach szesnastkowych (i E w notacji naukowej) są duże | ||
* showbase - dodaje odpowiednie nagłówki dla hex i oct | ||
* showpoint - nakazuje zawsze wypisać kropkę w liczbach float | ||
* showpos - dodaje `+' przed liczbą dodatnią | ||
* unitbuf - wyłącza buforowanie dla strumienia | ||
* | ||
* MANIPULATORY: | ||
* Wejścia: | ||
* ws - ignorowanie wiodących białych znaków w operacjach wejścia | ||
* setw (size_t) - ograniczenie bufora dla wprowadzanych znaków | ||
* Wyjścia: | ||
* flush, ends, endl - opróżnienie bufora, wysłanie znaku zerowego, wysłanie znaku '\n' | ||
* setbase(8 lub 16) - ustawia podstawę liczby | ||
* setfill(znak), jak cout.fill(znak) - ustawia znak wypełnienia | ||
* setprecision(), jak cout.precision() - ustawia ilość cyfr rozwinięcia | ||
* setw() , jak width() - ustawia min. szerokość pola | ||
* setiosflags, resetiosflags() - ustawia, kasuje flagi formatowania | ||
* | ||
*/ | ||
|
||
int main(int argc, char **argv){ | ||
int li = 100; | ||
float lf = 12.789; | ||
|
||
//FUNKCJA fmtflags flags (fmtflags fmtfl); | ||
//cout.flags (ios::right | ios::hex | ios::showbase); //ustawianie flag fmtflags jako typu | ||
ios_base::fmtflags fx; //deklaracja zmiennej typu fmtflags | ||
//fx &= ~cout.basefield; // unset basefield bits | ||
fx |= cout.hex; | ||
fx |= cout.showbase; | ||
|
||
cout.flags(fx); | ||
cout << li << endl; | ||
|
||
//FUNKCJA fmtflags setf (fmtflags fmtfl, fmtflags mask); | ||
cout.setf (ios::right, ios::adjustfield);// selektywne modyfikowanie flag | ||
//cout.setf (ios_base::oct, ios_base::basefield); //użycie fmtflags jako stałych klasy | ||
//FUNKCJA fmtflags setf (fmtflags fmtfl); | ||
//cout.setf (ios_base::showbase); | ||
//cout.setf (ios::oct, ios::basefield); //użycie fmtflags jako dziedziczonych stałych klasy | ||
//cout.setf (ios::showbase); | ||
//cout.setf (cout.oct, cout.basefield); //użycie fmtflags jako stałych obiektu | ||
//cout.setf (cout.showbase); | ||
//cout.setf( 0, ios::floatfield ); //przywrócenie stanu domyślnego floatfield | ||
|
||
cout.precision(5); | ||
cout.fill('*'); //ustawia znak wypełnienia pola | ||
cout.width (20); //ustawienie minimalnej szerokości pola | ||
cout << li << endl; | ||
cout << lf << endl; | ||
cout << M_PI << endl; | ||
|
||
//MANIPULATORY | ||
//setiosflags (ios_base::fmtflags mask); | ||
//cout << hex; | ||
//cout << setiosflags (ios::showbase | ios::uppercase); | ||
//cout << dec << showbase << uppercase; | ||
|
||
//cout << hex; | ||
//cout << showpoint << f << endl; | ||
|
||
string s; | ||
cin >> ws >> s; | ||
cout << s << endl; | ||
|
||
//http://www.cplusplus.com/reference/cstdio/printf/ | ||
//%[flags][width][.precision][length]specifier | ||
printf("%e\n", 10*M_PI); // 3.141593e+001 | ||
printf("%12f\n", 10*M_PI); // 31.415927 | ||
printf("%12.4f\n", 10*M_PI); // 31.4159 | ||
printf("%12.4d\n", 3); // 0003 | ||
printf("Hex: %#x\nOct: %#o\n", 10, 10); | ||
printf("Napis: %20s", "Ahoj"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> // std::cout, std::ios, std::endl | ||
#include <iomanip> // std::setiosflags | ||
#include <cstdio> // printf | ||
#include <math.h> //stała M_PI | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char **argv){ | ||
|
||
int tab[4]; | ||
for (int i = 0; i < 4; i++) | ||
tab[i] = i; | ||
|
||
printf("\e[1;40H%i", tab[1]); | ||
printf("\e[4;20H%i", tab[2]); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
float horner_it(int k, float tbwsp[], float x) { | ||
int i; | ||
float wartosc = tbwsp[0]; | ||
for (i=1; i<=k; i++) | ||
wartosc = wartosc*x + tbwsp[i]; | ||
return wartosc; | ||
} | ||
|
||
// W(x) = 2x^3 + 3x^2 + 5x + 4 | ||
// W(x) = x (2x^2 + 3x + 5) +4 | ||
// W(x) = x (x (2x + 3) + 5) + 4 | ||
float horner_re(int k, float tbwsp[], float x) { | ||
if (k==0) | ||
return tbwsp[0]; | ||
else | ||
return horner_re(k-1,tbwsp,x)*x+tbwsp[k]; | ||
} | ||
|
||
void drukujw(int st, float tbwsp[]) { | ||
int i; | ||
for (i=0; i<st-1; i++) { | ||
cout << tbwsp[i] << "x^" << st-i << " + "; | ||
} | ||
cout << tbwsp[i] << "x + " << tbwsp[i+1]; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
float *tbwsp; | ||
float x = 0; | ||
int stopien = 0; | ||
cout << "Podaj stopień wielomianu: "; | ||
cin >> stopien; | ||
tbwsp = new float [stopien+1]; | ||
|
||
cout << "Obliczanie wartości wielomianu dla " << stopien+1 << " współczynników i argumentu." << endl; | ||
for (int i=0; i<=stopien; i++) { | ||
cout << "Podaj współczynnik przy potędze " << stopien-i << ": "; | ||
cin >> tbwsp[i]; | ||
} | ||
|
||
cout << "Podaj argument... "; | ||
cin >> x; | ||
|
||
cout << "Wartość wielomianu o postaci: "; | ||
drukujw(stopien, tbwsp); | ||
cout << "\ndla x = " << x << " wynosi: "; | ||
cout << horner_re(stopien,tbwsp,x) << endl; | ||
cout << horner_it(stopien,tbwsp,x) << endl; | ||
cout << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
double a, b; // zmienne pomocnicze - wspó³rzedne losowanego punktu | ||
long T = 0; // dziêki typowi long mo¿emy losowac wiele punktów | ||
long R; | ||
long n; | ||
srand(time(NULL)); // inicjacja funkcji rand() | ||
cout << "Na podstawie ilu punktow znalezc wartosc liczby pi? "; | ||
cin >> n; | ||
for(R=0; R<n; R++) | ||
{ | ||
a = (double)rand()/(RAND_MAX); // losujemy liczby rzeczywiste | ||
b = (double)rand()/(RAND_MAX); // z zakresu <0,1> | ||
if (a*a+b*b<=1) T++; // jeœli punkt nale¿y do ko³a to zwiêkszamy licznik | ||
} | ||
cout << "liczba pi ma wartosc : " << (double)(4*T)/R << endl; | ||
|
||
T = 0; | ||
for(R=0; R<n; R++) | ||
{ | ||
a = (double)rand()/(RAND_MAX); // losujemy liczby rzeczywiste | ||
b = (double)rand()/(RAND_MAX); // z zakresu <0,1> | ||
if (a*a+b*b<=1) T++; // jeœli punkt nale¿y do ko³a to zwiêkszamy licznik | ||
} | ||
cout << "liczba pi ma wartosc : " << (double)(4*T)/R << endl; | ||
|
||
cout << "Liczba Pi: " << M_PI << endl; | ||
|
||
system("PAUSE"); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_project_file> | ||
<FileVersion major="1" minor="6" /> | ||
<Project> | ||
<Option title="lista-stos" /> | ||
<Option pch_mode="2" /> | ||
<Option compiler="gcc" /> | ||
<Build> | ||
<Target title="Debug"> | ||
<Option output="bin/Debug/lista-stos" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj/Debug/" /> | ||
<Option type="1" /> | ||
<Option compiler="gcc" /> | ||
<Compiler> | ||
<Add option="-g" /> | ||
</Compiler> | ||
</Target> | ||
<Target title="Release"> | ||
<Option output="bin/Release/lista-stos" prefix_auto="1" extension_auto="1" /> | ||
<Option object_output="obj/Release/" /> | ||
<Option type="1" /> | ||
<Option compiler="gcc" /> | ||
<Compiler> | ||
<Add option="-O2" /> | ||
</Compiler> | ||
<Linker> | ||
<Add option="-s" /> | ||
</Linker> | ||
</Target> | ||
</Build> | ||
<Compiler> | ||
<Add option="-Wall" /> | ||
<Add option="-fexceptions" /> | ||
</Compiler> | ||
<Unit filename="lista.cpp"> | ||
<Option target="Release" /> | ||
</Unit> | ||
<Unit filename="lista.h"> | ||
<Option target="Release" /> | ||
</Unit> | ||
<Unit filename="main.cpp" /> | ||
<Unit filename="stos.cpp"> | ||
<Option target="Release" /> | ||
</Unit> | ||
<Unit filename="stos.h"> | ||
<Option target="Release" /> | ||
</Unit> | ||
<Extensions> | ||
<code_completion /> | ||
<debugger /> | ||
</Extensions> | ||
</Project> | ||
</CodeBlocks_project_file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# depslib dependency file v1.0 | ||
1488713935 source:/home/smaster/github/linetc/cpp/lista-stos/lista.cpp | ||
<iostream> | ||
"lista.h" | ||
|
||
1488713978 /home/smaster/github/linetc/cpp/lista-stos/lista.h | ||
|
||
1488714123 source:/home/smaster/github/linetc/cpp/lista-stos/main.cpp | ||
<iostream> | ||
"stos.h" | ||
|
||
1488711573 /home/smaster/github/linetc/cpp/lista-stos/stos.h | ||
"lista.h" | ||
|
||
1488711484 source:/home/smaster/github/linetc/cpp/lista-stos/stos.cpp | ||
"stos.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_layout_file> | ||
<FileVersion major="1" minor="0" /> | ||
<ActiveTarget name="Debug" /> | ||
<File name="lista.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="62" topLine="0" /> | ||
</Cursor> | ||
</File> | ||
<File name="stos.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="0" topLine="0" /> | ||
</Cursor> | ||
</File> | ||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="478" topLine="0" /> | ||
</Cursor> | ||
</File> | ||
<File name="lista.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> | ||
<Cursor> | ||
<Cursor1 position="52" topLine="0" /> | ||
</Cursor> | ||
</File> | ||
</CodeBlocks_layout_file> |
Oops, something went wrong.