Advertisement
Meks__

Untitled

Jan 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.28 KB | None | 0 0
  1. // KALKULATOR - Nzawa.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <math.h>>
  7.  
  8. float dodaj(float a, float b)
  9. {
  10.     float dodaj_ab = a + b;
  11.     return dodaj_ab;
  12. }
  13. float odejmij(float a, float b)
  14. {
  15.     float odejmij_ab = a - b;
  16.     return odejmij_ab;
  17. }
  18. float pomnoz(float a, float b)
  19. {
  20.     float pomnoz_ab = a * b;
  21.     return pomnoz_ab;
  22. }
  23. float podziel(float a, float b)
  24. {
  25.     float podziel_ab = a / b;
  26.     return podziel_ab;
  27. }
  28. float podnies_do_potegi(float a, float b)
  29. {
  30.     float podnies_do_potegi = pow(a, b);
  31.  
  32.     return podnies_do_potegi;
  33. }
  34. float pierwiastek(float a, float b)
  35. {
  36.     float pierwiastek_ab = pow(a, 1 / b);
  37.     return pierwiastek_ab;
  38. }
  39. int _tmain(int argc, _TCHAR* argv[])
  40. {
  41.     printf("Witam w programie \"KALKULATOR\" wykonanym przez: \n");
  42.     printf("Hubert Filipiak AIR nhiestacjonarne I semestr .\n\n");
  43.     int wybor;
  44.     printf("Wybierz jakie dzialanie chcesz wybrac: \n");
  45.     printf("[1]Dodawanie\n");
  46.     printf("[2]Odejmowanie\n");
  47.     printf("[3]Mnozenie\n");
  48.     printf("[4]Dzielenie\n");
  49.     printf("[5]Potegowanie\n");
  50.     printf("[6]Pierwiastkowanie\n");
  51.     printf("[7]Funkcja Sinus\n");
  52.     printf("[8]Funkcja Cosinus\n");
  53.     printf("[9]Silnia\n\n");
  54.     printf("Napisz (cyfre) jakie dzialanie wykonac: ");
  55.     scanf_s("%d", &wybor);
  56.     printf("\n");
  57.     switch (wybor)
  58.     {
  59.  
  60.     case 1:
  61.         float a, b, v, i;
  62.  
  63.         printf("Podaj liczbe a: ");
  64.         scanf_s("%f", &a);
  65.         printf("Podaj liczbe b: ");
  66.         scanf_s("%f", &b);
  67.         v = dodaj(a, b);
  68.         printf("Wynik dodawnia to: %.2f\n", v);
  69.         break;
  70.  
  71.     case 2:
  72.        
  73.         printf("Podaj liczbe a: ");
  74.         scanf_s("%f", &a);
  75.         printf("Podaj liczbe b: ");
  76.         scanf_s("%f", &b);
  77.     v = odejmij(a, b);
  78.         printf("Wynik odejmowania to: %.2f\n", v);
  79.         break;
  80.  
  81.     case 3:
  82.         printf("Podaj liczbe a: ");
  83.         scanf_s("%f", &a);
  84.         printf("Podaj liczbe b: ");
  85.         scanf_s("%f", &b);
  86.         v = pomnoz(a, b);
  87.         printf("Wynik mnozenie to: %.2f\n", v);
  88.         break;
  89.  
  90.     case 4:
  91.         if (b == 0)
  92.         {
  93.             printf("Nie dzielimy przez zero.\n");
  94.         }
  95.         else
  96.         {
  97.             printf("Podaj liczbe a: ");
  98.             scanf_s("%f", &a);
  99.             printf("Podaj liczbe b: ");
  100.             scanf_s("%f", &b);
  101.             v = podziel(a, b);
  102.             printf("Wynik dzielenia to: %.2f\n", v);
  103.         }
  104.         break;
  105.     default:
  106.         printf("Nie ma takiego dzialania");
  107.         break;
  108.     case 5:
  109.         printf("Podaj liczbe a: ");
  110.         scanf_s("%f", &a);
  111.         printf("Podaj liczbe b: ");
  112.         scanf_s("%f", &b);
  113.         v = podnies_do_potegi(a, b);
  114.         printf("Wynik potegowania to: %.2f\n", v);
  115.         break;
  116.     case 6:
  117.         printf("Podaj liczbe a: ");
  118.         scanf_s("%f", &a);
  119.         printf("Podaj liczbe b: ");
  120.         scanf_s("%f", &b);
  121.         v = pierwiastek (a, b);
  122.         printf("Wynik pierwiastkowania to: %.2f\n", v);
  123.         break;
  124.     case 7:
  125.         printf("Podaj liczbe a: ");
  126.         scanf_s("%f", &a);
  127.         printf("Podaj liczbe b: ");
  128.         scanf_s("%f", &b);
  129.  
  130.         break;
  131.     case 8:
  132.         printf("Podaj liczbe a: ");
  133.         scanf_s("%f", &a);
  134.         printf("Podaj liczbe b: ");
  135.         scanf_s("%f", &b);
  136.  
  137.         break;
  138.     case 9:
  139.         v = 1;
  140.         printf("Podaj liczbe: ");
  141.         scanf_s("%f", &a);
  142.         if (a<0)
  143.             printf("Wpisales liczbe ujemna, z ktorej nie mozna obliczyc n! \n");
  144.         else if (a>12)
  145.             printf("Wpisales za duza liczbe, najwieksza dopuszczalna to 12 \n");
  146.         else
  147.         {
  148.             i = a;
  149.             while (i>0)
  150.                 v *= i--;
  151.             printf("%.2f! wynosi %.2f \n", a, v);
  152.         }
  153.     }
  154.  
  155.     _getch();
  156.     return 0;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement