Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <string>
- using namespace std;
- float SUMA(float a, float b);
- float WARTOSC_BEZWZGLEDNA(float a);
- bool CZY_PARZYSTA(int a);
- void SZLACZEK(int d, char zn);
- float POTEGA(float x, int y);
- float OBWOD_TROJKATA(float a, float b, float c);
- unsigned long long SILNIA(int a);
- int MAX(int a, int b, int c);
- vector <int> DZIELNIKI(int a);
- float ILORAZ(int a, int b);
- void PODZIELNOSC(int a=0, float b=0.0);
- int LICZBA_CYFR(int a);
- int SUMA_CYFR(int a);
- auto POLE_TROJKATA(float a, float h) -> decltype(a*h/2) {return a*h/2;}
- float POLE_TROJKATA(float x1, float y1, float x2, float y2, float x3, float y3);
- int main()
- {
- // ZADANIE 1
- cout<<"Zadanie 1"<<endl;
- cout<<SUMA(358.23, 34.23)<<endl;
- cout<<SUMA(11, 74.33)<<endl;
- cout<<SUMA(547.343, 34.23)<<endl;
- // ZADANIE 2
- cout<<"Zadanie 2"<<endl;
- cout<<WARTOSC_BEZWZGLEDNA(-4)<<endl;
- cout<<WARTOSC_BEZWZGLEDNA(-79.34)<<endl;
- cout<<WARTOSC_BEZWZGLEDNA(10)<<endl;
- // ZADANIE 3
- cout<<"Zadanie 3"<<endl;
- cout<<CZY_PARZYSTA(15)<<endl;
- cout<<CZY_PARZYSTA(14)<<endl;
- cout<<CZY_PARZYSTA(-18)<<endl;
- // ZADANIE 4
- cout<<"Zadanie 4"<<endl;
- SZLACZEK(7, 'x');
- cout<<endl;
- SZLACZEK(21, 'p');
- cout<<endl;
- SZLACZEK(-11, 'g');
- cout<<endl;
- // ZADANIE 5
- cout<<"Zadanie 5"<<endl;
- cout<<POTEGA(-15, 2)<<endl;
- cout<<POTEGA(-17, 3)<<endl;
- cout<<POTEGA(10.97, 7)<<endl;
- cout<<POTEGA(2, 10)<<endl;
- // ZADANIE 6
- cout<<"Zadanie 6"<<endl;
- float tab[3] = {OBWOD_TROJKATA(1,3,7), OBWOD_TROJKATA(-8, 10, 12), OBWOD_TROJKATA(1,3,3)};
- for(int i=0;i<(end(tab) - begin(tab));i++){
- if(tab[i]==-1){
- cout<<"Nie da sie utworzyc trojkata!"<<endl;
- }else{
- cout<<"Obwod trojkata wynosi: "<<tab[i]<<endl;
- }
- }
- // ZADANIE 7
- cout<<"Zadanie 7"<<endl;
- cout<<SILNIA(0)<<endl;
- cout<<SILNIA(6)<<endl;
- cout<<SILNIA(20)<<endl;
- // ZADANIE 8
- cout<<"Zadanie 8"<<endl;
- cout<<MAX(2, 7, 10)<<endl;
- cout<<MAX(-2, 7, 15)<<endl;
- cout<<MAX(8, 8, 9)<<endl;
- cout<<MAX(8, 9, 8)<<endl;
- cout<<MAX(9, 8, 8)<<endl;
- // ZADANIE 9
- cout<<"Zadanie 9"<<endl;
- vector <int> tab_view;
- tab_view = DZIELNIKI(10);
- for(vector<int>::const_iterator i = tab_view.begin(); i != tab_view.end(); i++){
- cout<<*i<<" ";
- }
- cout<<endl;
- tab_view = DZIELNIKI(180);
- for(vector<int>::const_iterator i = tab_view.begin(); i != tab_view.end(); i++){
- cout<<*i<<" ";
- }
- cout<<endl;
- tab_view = DZIELNIKI(238474);
- for(vector<int>::const_iterator i = tab_view.begin(); i != tab_view.end(); i++){
- cout<<*i<<" ";
- }
- cout<<endl;
- // ZADANIE 10
- cout<<"Zadanie 10"<<endl;
- float tab2[3] = {ILORAZ(0, -2), ILORAZ(2, 0), ILORAZ(3, 4)};
- for(int i=0;i<(end(tab2) - begin(tab2));i++){
- if(tab2[i]==-2){
- cout<<"Conajmniej jedna podana liczba nie jest naturalna!"<<endl;
- }else if(tab2[i]==-1){
- cout<<"Nie mozna dzielic przez zero!"<<endl;
- }else{
- cout<<tab2[i]<<endl;
- }
- }
- // ZADANIE 11 - wersja tymczasowa !!!!
- cout<<"Zadanie 11"<<endl;
- PODZIELNOSC();
- cout<<endl;
- // ZADANIE 12
- cout<<"Zadanie 12"<<endl;
- cout<<LICZBA_CYFR(123456)<<endl;
- cout<<LICZBA_CYFR(123456789)<<endl;
- cout<<LICZBA_CYFR(123)<<endl;
- // ZADANIE 13
- cout<<"Zadanie 13"<<endl;
- cout<<SUMA_CYFR(123)<<endl;
- cout<<SUMA_CYFR(123456)<<endl;
- cout<<SUMA_CYFR(123456789)<<endl;
- int suma = SUMA_CYFR(1234567891);
- while(true){
- if (to_string(suma).length()>1){
- suma = SUMA_CYFR(suma);
- }else{
- cout<<"Wynik jednocyforwy sumy: "<<suma<<endl;
- break;
- }
- }
- // ZADANIE 14
- cout<<"Zadanie 14"<<endl;
- cout<<POLE_TROJKATA(10, 6)<<endl;
- cout<<POLE_TROJKATA(17.77, 1.23)<<endl;
- cout<<POLE_TROJKATA(12, 17)<<endl;
- // ZADANIE 15
- cout<<"Zadanie 15"<<endl;
- cout<<POLE_TROJKATA(1,1,4,1,1,5)<<endl;
- cout<<POLE_TROJKATA(6,7,8,9,12,51)<<endl;
- cout<<POLE_TROJKATA(0,1,4,7,1,5)<<endl;
- return 0;
- }
- float SUMA(float a, float b){
- return a + b;
- }
- float WARTOSC_BEZWZGLEDNA(float a){
- if (a < 0) {
- a = -a;
- }
- return a;
- }
- bool CZY_PARZYSTA(int a){
- if (a % 2 == 0){
- return true;
- }else{
- return false;
- }
- }
- void SZLACZEK(int d, char zn){
- for(d;d>0;d--){
- cout<<zn;
- }
- }
- float POTEGA(float x, int y){
- if (y > 0) return x * POTEGA(x, y-1);
- else return 1;
- }
- float OBWOD_TROJKATA(float a, float b, float c){
- if((a+b>c)&&(b+c>a)&&(a+c>b)){
- return a+b+c;
- }else{
- return -1;
- }
- }
- unsigned long long SILNIA(int a){
- if(a>1){
- return a * SILNIA(a-1);
- }else{
- return 1;
- }
- }
- int MAX(int a, int b, int c){
- if((a>b)&&(a>c)){
- return a;
- }else if(b>c){
- return b;
- }else{
- return c;
- }
- }
- vector <int> DZIELNIKI(int a){
- vector <int> tab;
- for(int i=1;i<=a;i++){
- if(a%i == 0){
- tab.push_back(i);
- }
- }
- return tab;
- }
- float ILORAZ(int a, int b){
- if((a>0)&&(b>0)){
- return float(a)/b;
- }else if(b==0){
- return -1;
- }else{
- return -2;
- }
- }
- void PODZIELNOSC(int a, float b){
- if(a == 0){
- cout<<"Podaj ilocyfrowe liczby Cie interesuja: ";
- cin>>a;
- }
- if (b == 0.0){
- cout<<"Podaj, przez co maja byc podzielne: ";
- cin>>b;
- }
- if((a>0)&&(b!=0)){
- int max_c, min_c;
- if(b>0){
- max_c = 9;
- min_c = 1;
- for(int i=2;i<=a;i++){
- max_c = max_c * 10 + 9;
- min_c = min_c * 10;
- }
- cout<<"Twoje liczby to: ";
- for(int i=ceil(min_c/b);true;i++){
- if(i*b>max_c){
- break;
- }else{
- cout<<i*b<<",";
- }
- }
- }else if(b<0){
- max_c = -9;
- min_c = -1;
- for(int i=2;i<=a;i++){
- max_c = max_c * 10 - 9;
- min_c = min_c * 10;
- }
- cout<<"Twoje liczby to: ";
- for(int i=ceil(min_c/b);true;i++){
- if(i*b<max_c){
- break;
- }else{
- cout<<i*b<<",";
- }
- }
- }
- }else{
- cout<<"Wprowadzone paramety sa nieprawidlowe";
- }
- }
- int LICZBA_CYFR(int a){
- string b = to_string(a);
- return b.length();
- }
- int SUMA_CYFR(int a){
- int suma = 0;
- int breaker = to_string(a).length();
- for(int i=1;i<breaker;i++){
- suma = suma + a%10;
- a = a/10;
- }
- return suma + a;
- }
- float POLE_TROJKATA(float x1, float y1, float x2, float y2, float x3, float y3){
- float a = pow(pow((x1 - x2 > 0) ? x1 - x2 : - (x1 - x2),2)+pow((y1 - y2 > 0) ? y1 - y2 : - (y1 - y2),2),0.5);
- float b = pow(pow((x2 - x3 > 0) ? x2 - x3 : - (x2 - x3),2)+pow((y2 - y3 > 0) ? y2 - y3 : - (y2 - y3),2),0.5);
- float c = pow(pow((x3 - x1 > 0) ? x3 - x1 : - (x3 - x1),2)+pow((y3 - y1 > 0) ? y3 - y1 : - (y3 - y1),2),0.5);
- float p = (a + b + c) / 2;
- return pow(p*(p-a)*(p-b)*(p-c),0.5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement