Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zad1
- #include <iostream>
- using namespace std;
- int SUMA (int a, int b)
- {
- int s=a+b;
- return s;
- }
- int main()
- {
- int a,b;
- cout << "Podaj a i b: ";
- cin >> a >> b;
- cout << SUMA(a,b) << endl;
- return 0;
- }
- //zad2
- #include <iostream>
- using namespace std;
- int WARTOSC_BEZWZGLEDNA (int x)
- {
- if (x<0)
- {
- x=x*-1;
- }
- return x;
- }
- int main()
- {
- int x;
- cout << "Podaj liczbe: ";
- cin >> x;
- cout << WARTOSC_BEZWZGLEDNA (x) << endl;
- return 0;
- }
- //zad3
- #include <iostream>
- using namespace std;
- bool CZY_PARZYSTA (int x)
- {
- if (x%2==0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- int main()
- {
- int x;
- cout << "Podaj liczbe zeby sprawdzic czy jest parzysta: ";
- cin >> x;
- cout << CZY_PARZYSTA (x) << endl;
- return 0;
- }
- //zad4
- #include <iostream>
- using namespace std;
- void SZLACZEK (int x, char y)
- {
- for (int i=0;i<x;i++)
- {
- cout << y;
- }
- }
- int main()
- {
- int x;
- char y;
- cout << "Podaj dlugosc szlaczka: ";
- cin >> x;
- cout << "Podaj znak: ";
- cin >> y;
- SZLACZEK (x,y);
- return 0;
- }
- //zad5
- #include <iostream>
- using namespace std;
- int x,y,s;
- int POTEGA (int x, int y)
- {
- int s=1;
- for (int i=0;i<y;i++)
- {
- s=s*x;
- }
- return s;
- }
- int main()
- {
- cout << "Podaj podstawe potegi: ";
- cin >> x;
- cout << "Podaj wykladnik potegi: ";
- cin >> y;
- cout << POTEGA (x,y);
- return 0;
- }
- //zad6
- #include <iostream>
- using namespace std;
- int a,b,c,ob;
- int OBWOD_TROJKATA (int a, int b, int c)
- {
- if (a<=0 || b<=0 || c<=0)
- {
- cout << "Nie da sie zbudowac trojkata, wartosc(i) sa ujemne";
- return -1;
- }
- else if (a+b>c&&a+c>b&&b+c>a)
- {
- int ob=a+b+c;
- return ob;
- }
- else
- {
- cout << "Nie da sie zbudowac trojkata";
- return -1;
- }
- }
- int main()
- {
- cout << "Podaj dlugosci bokow trojkata: ";
- cin >> a >> b >> c;
- cout << OBWOD_TROJKATA(a,b,c) <<endl;
- return 0;
- }
- //zad7
- #include <iostream>
- using namespace std;
- int n;
- int SILNIA (int n)
- {
- if (n<0)
- {
- cout << "Blad, niewlasciwe dane";
- return 0;
- }
- else if (n>=0&&n<2)
- {
- return 1;
- }
- else
- {
- return n*SILNIA(n-1);
- }
- }
- int main()
- {
- cout << "Podaj liczbe zeby obliczyc silnie: ";
- cin >> n;
- cout << SILNIA(n);
- return 0;
- }
- //zad8
- #include <iostream>
- using namespace std;
- int a,b,c;
- /*void MAX (int a,int b,int c)
- {
- if (a>b)
- {
- if (b>c)
- {
- cout << "a: " << a << " b: " << b << " c: " << c;
- }
- else
- {
- cout << "a: " << a << " c: "<< c << " b: " <<b;
- }
- }
- else if (b>c)
- {
- if (a>c)
- {
- cout << "b: " << b << " a: " << a << " c: " << c;
- }
- else
- {
- cout << "b: " << b << " c: " << c << " a: " << a;
- }
- }
- else
- {
- if (a>b)
- {
- cout << "c: " << c << " a: " << a << " b: " << b;
- }
- else
- {
- cout << "c: " << c << " b: " << b << " a: " << a;
- }
- }
- }
- */
- int MAX(int a,int b,int c)
- {
- if (a>b)
- {
- if (a>c)
- {
- return a;
- }
- else if (b>c)
- {
- return b;
- }
- else
- {
- return c;
- }
- }
- else if (b>c)
- {
- return b;
- }
- else
- {
- return c;
- }
- }
- int main()
- {
- cout << "Podaj 3 liczby: ";
- cin >> a >> b >> c;
- cout << MAX(a,b,c);
- //MAX(a,b,c);
- return 0;
- }
- //zad9
- #include <iostream>
- using namespace std;
- int n;
- void DZIELNIKI (int n)
- {
- if (n<0)
- {
- cout << "Podana liczba " << n << " nie jest liczba naturalna";
- }
- else
- {
- cout << "Dzielniki liczby " << n << ": ";
- for (int i=n;i>0;i--)
- {
- if (n%i==0)
- {
- cout << i << " ";
- }
- }
- }
- }
- int main()
- {
- cout << "Podaj liczbe zeby znalezc dzielniki: ";
- cin >> n;
- DZIELNIKI (n);
- return 0;
- }
- //zad10
- #include <iostream>
- using namespace std;
- int a,b,x;
- int ILORAZ(int a, int b)
- {
- if (a<0||b<0)
- {
- x=-2;
- return -2;
- }
- else if (b==0)
- {
- x=-1;
- return -1;
- }
- else
- {
- x=a*b;
- return x;
- }
- }
- int main()
- {
- cout << "Podaj liczby zeby obliczyc ich iloraz: ";
- cin >> a >> b;
- cout << ILORAZ(a,b) << endl;
- if (x==-1)
- {
- cout << "Nie dziel przez 0";
- }
- else if (x==-2)
- {
- cout << "Ktoras z podanych liczb nie jest liczba naturalna";
- }
- return 0;
- }
- //zad11
- #include <iostream>
- #include <math.h>
- using namespace std;
- int a,b,x;
- void PODZIELNOSC(int a, int b)
- {
- x=1;
- for(int i=0; i<a-1; i++)
- {
- x=x*10;
- }
- cout << "Liczby " << a << " cyfrowe podzielne przez " << b << " to: ";
- for (int i=x;i<x*10-1;i++)
- {
- if (i%b==0)
- {
- cout << i << " ";
- }
- }
- }
- int main()
- {
- cout << "Podaj ilocyfrowe liczby cie interesuja: ";
- cin >> a;
- cout << "Podaj przez co maja byc podzielne: ";
- cin >> b;
- PODZIELNOSC(a,b);
- return 0;
- }
- //zad12
- #include <iostream>
- using namespace std;
- int x;
- int LICZBA_CYFR(int x)
- {
- int z=x;
- int i=0;
- if (x<0)
- {
- cout << "Podana liczba nie jest liczba naturalna";
- }
- else
- {
- for (i;x>0;i++)
- {
- x=x/10;
- }
- cout << "Ilosc cyfr liczby " << z <<": ";
- return i;
- }
- }
- int main()
- {
- cout << "Podaj liczbe naturalna: ";
- cin >> x;
- cout << LICZBA_CYFR(x);
- return 0;
- }
- //zad13
- #include <iostream>
- using namespace std;
- int x;
- void SUMA_CYFR(int x)
- {
- /*if(x>0)
- return x%10 + SUMA_CYFR(x/10);
- return 0;
- */
- if (x<0)
- {
- cout << "Podana liczba nie jest liczba naturalna" << endl;
- }
- else
- {
- do
- {
- int s=0;
- while (x>0)
- {
- s+=x%10;
- x/=10;
- };
- x=s;
- cout << "Suma cyfr wynosi: " << x << endl;
- }
- while (x>9);
- cout << "Suma ostateczna wynosi: " << x << endl;
- }
- }
- int main()
- {
- cout << "Podaj liczbe: ";
- cin >> x;
- SUMA_CYFR(x);
- return 0;
- }
- //zad14,15
- #include <iostream>
- #include <math.h>
- using namespace std;
- float POLE_TROJKATA(float a,float h)
- {
- if (a<=0||h<=0)
- {
- cout << "Niewlasciwa dlugosc podstawy lub wysokosci, ";
- return 0;
- }
- else
- {
- float p=(a*h)/2;
- cout << "Pole trojkata wynosi: ";
- return p;
- }
- }
- float POLE_TROJKATA(float x1,float y1,float x2,float y2,float x3,float y3)
- {
- float a,b,c,p,s;
- a=sqrt(pow(x1-x2,2)+pow(y1-y2,2));
- b=sqrt(pow(x2-x3,2)+pow(y2-y3,2));
- c=sqrt(pow(x1-x3,2)+pow(y1-y3,2));
- if (a<0||b<0||c<0||a+b>c||a+c>b||b+c>a)
- {
- p=(a+b+c)*0.5;
- s=sqrt(p*(p-a)*(p-b)*(p-c));
- //s = sqrt(p * (p-a) * (p-b) * (p-c));
- cout << "Pole trojkata wynosi: " << s;
- }
- else
- {
- cout << "Nie da sie zbudowac trojkata";
- }
- }
- int main()
- {
- int f;
- float a,h,x1,x2,x3,y1,y2,y3;
- cout << "Wywolane funkcje dla przykladowych wartosci: " << endl;
- POLE_TROJKATA(-1,0,1,2,1,-1);
- cout << endl;
- POLE_TROJKATA(5,1,-2,3,0,-2);
- cout << endl;
- cout << POLE_TROJKATA(10,5) << endl;
- cout << POLE_TROJKATA(0,2) << endl;
- cout << POLE_TROJKATA(9,3) << endl;
- cout << POLE_TROJKATA(5,-2) << endl;
- cout << endl << "--------------------------------------" << endl;
- cout << "Liczenie pola trojkata z podanej wysokosci i podstawy - wpisz 1" << endl << "Liczenie pola trojkata z wspolrzednych - wpisz 2" << endl;
- cin >> f;
- if (f==1)
- {
- cout << "Podaj dlugosc podstawy i wysokosc: ";
- cin >> a >> h;
- cout << POLE_TROJKATA(a,h);
- }
- else if (f==2)
- {
- cout << "Podaj wspolrzedne:" << endl;
- cout << "punktu A, x i y: ";
- cin >> x1 >> y1;
- cout << "punktu B, x i y: ";
- cin >> x2 >> y2;
- cout << "punktu C, x i y: ";
- cin >> x3 >> y3;
- cout << POLE_TROJKATA(x1,y1,x2,y2,x3,y3);
- }
- else
- {
- cout << "Podano niewlasciwa wartosc";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment