Advertisement
lukusm

Untitled

Apr 8th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /*
  2.  *  nazwa projektu:
  3.  *  wersja projektu:
  4.  *  opis:
  5.  */
  6.  
  7. #include <iostream>
  8. #include <windows.h>
  9. #include <cmath>
  10. using namespace std;
  11.  
  12. /*********** SEKCJA DEKLARACYJNA ***********/
  13. //ZADANIE 1
  14. void wypisz_dane() {
  15.     string imie = ""; // tu uzupelnic
  16.     string nazwisko = ""; // tu uzupelnic
  17.     cout<<"Imie: "<<imie<<endl;
  18.     cout<<"Nazwisko: "<<nazwisko<<endl<<endl;
  19. }
  20.  
  21. //ZADANIE 2
  22. int silnia(int x) {
  23.     if(x==0)
  24.         return 1;
  25.     else if(x>=1)
  26.         return x*silnia(x-1);
  27. }
  28.  
  29. float newton(int n, int k) {
  30.     return silnia(n)/(silnia(k)*silnia(n-k));
  31. }
  32.  
  33. //ZADANIE 3
  34. float iloczyn(int n) {
  35.     float suma=0.0;
  36.     for(int k=1; k<=n; k++) {
  37.         float element = (k*k*k)/(2*k+1);
  38.         suma+=element;
  39.     }
  40.     return suma;
  41. }
  42.  
  43. //ZADANIE 4
  44. float poleKuli(float r) {
  45.     return 4*M_PI*r*r;
  46. }
  47.  
  48. //ZADANIE 5
  49. float suma(float a, float b) {
  50.     return a+b;
  51. }
  52. /*************** SEKCJA MAIN ***************/
  53. int main() {
  54.   system("chcp 1250>NUL");
  55.   //ZADANIE 1
  56.   wypisz_dane();
  57.  
  58.   //ZADANIE 2
  59.   int a = 5;
  60.   cout<<"Silnia liczby "<<a<<" wynosi "<<silnia(a)<<endl<<endl;
  61.   int n=7;
  62.   int k=2;
  63.   cout<<"Wartosc symbolu newtona dla n="<<n<<", k="<<k<<" wynosi "<<newton(n,k)<<endl<<endl;
  64.  
  65.   //ZADANIE 3
  66.   int N;
  67.   cout<<"Podaj N:";
  68.   cin>>N;
  69.   cout<<"Wartosc iloczynu dla N="<<N<<" wynosi "<<iloczyn(N)<<endl<<endl;
  70.  
  71.   //ZADANIE 4
  72.   cout<<"Podaj promien kuli (z dokladnoscia do milimetra po kropce):";
  73.   float promien;
  74.   cin>>promien;
  75.   cout<<"Pole kuli o promieniu = "<<promien<<" wynosi "<<poleKuli(promien)<<endl<<endl;
  76.  
  77.   //ZADANIE 5
  78.   float s1, s2;
  79.   for(int i=1; i<=5; i++) {
  80.     cout<<"Podaj 1. liczbe:";
  81.     cin>>s1;
  82.     cout<<"Podaj 2. liczbe:";
  83.     cin>>s2;
  84.     cout<<"Suma liczb "<<s1<<" i "<<s2<<" wynosi "<<suma(s1,s2)<<endl;
  85.     }
  86.  
  87.   system("pause");
  88.   return 0;
  89. }
  90.  
  91. /************ SEKCJA DEFINICYJNA ***********/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement