Advertisement
DominikPasiut

Untitled

Jan 26th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.42 KB | None | 0 0
  1. #include "my_header.h"
  2.  
  3. int main()
  4. {
  5.  
  6.     do
  7.     {
  8.         printf("Kalkulator\n\nWybierz jedna z opcji\n\n");
  9.         puts("1 Dodawanie");
  10.         puts("2 Odejmowianie");
  11.         puts("3 Mnozenie");
  12.         puts("4 Dzielenie");
  13.         puts("5 Potegowanie");
  14.         puts("6 Zakoncz program");
  15.  
  16.         scanf("%c", &wyborProgramu);
  17.         system("CLS");
  18.  
  19.         switch (wyborProgramu)
  20.         {
  21.         case '1':
  22.         {
  23.             printf("Ile liczb chcesz dodac?\n");
  24.             scanf("%d", &iloscLiczb);
  25.  
  26.             arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double)); /* alokacja pamieci*/
  27.  
  28.             enterNumbers(arrayOfNumbers, iloscLiczb);       /* Przyjowanie liczb do tablicy*/
  29.  
  30.             result = adding(arrayOfNumbers, iloscLiczb);    /*Dodawanie*/
  31.  
  32.             writingOut(arrayOfNumbers, iloscLiczb, '+');            /*Wyświetlenie wyniku*/
  33.  
  34.             free(arrayOfNumbers);
  35.             result = 0;
  36.             iloscLiczb = 0;
  37.  
  38.             system("PAUSE");
  39.             break;
  40.         }
  41.  
  42.         case '2':
  43.         {
  44.             printf("Ile liczb chcesz odjac?\n");
  45.             scanf("%d", &iloscLiczb);
  46.  
  47.             arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
  48.  
  49.             enterNumbers(arrayOfNumbers, iloscLiczb);
  50.  
  51.             result = subtraction(arrayOfNumbers, iloscLiczb);
  52.  
  53.             writingOut(arrayOfNumbers, iloscLiczb, '-');
  54.  
  55.             free(arrayOfNumbers);
  56.             result = 0;
  57.             iloscLiczb = 0;
  58.  
  59.             system("pause");
  60.             break;
  61.         }
  62.  
  63.         case '3':
  64.         {
  65.             printf("Ile liczb chcesz pomnozyc?\n");
  66.             scanf("%d", &iloscLiczb);
  67.  
  68.             arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
  69.  
  70.             enterNumbers(arrayOfNumbers, iloscLiczb);
  71.  
  72.             result = multiplication(arrayOfNumbers, iloscLiczb);
  73.  
  74.             writingOut(arrayOfNumbers, iloscLiczb, '*');
  75.  
  76.  
  77.             free(arrayOfNumbers);
  78.             result = 0;
  79.             iloscLiczb = 0;
  80.  
  81.             system("pause");
  82.             break;
  83.         }
  84.  
  85.         case '4':
  86.         {
  87.             printf("Ile liczb chcesz podzielic?\n");
  88.             scanf("%d", &iloscLiczb);
  89.  
  90.             arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
  91.  
  92.             enterNumbers(arrayOfNumbers, iloscLiczb);
  93.  
  94.             for(int i = 0; i < iloscLiczb; i++)
  95.             {
  96.                 if(arrayOfNumbers[i] == 0.0)
  97.                 {
  98.                     printf("Nie dzieli sie przez 0\n");
  99.                     exit(1);
  100.                 }
  101.  
  102.             }
  103.  
  104.             result = division(arrayOfNumbers, iloscLiczb);
  105.  
  106.             writingOut(arrayOfNumbers, iloscLiczb, '/');
  107.  
  108.             free(arrayOfNumbers);
  109.             result = 0;
  110.             iloscLiczb = 0;
  111.  
  112.             system("pause");
  113.             break;
  114.         }
  115.  
  116.         case '5':
  117.         {
  118.             printf("Podaj podstawe: \n");
  119.             scanf("%lf", &numberIndex);
  120.             printf("Podaj wykladnik: \n");
  121.             scanf("%d", &exponent);
  122.  
  123.             result = exponentiation(numberIndex, exponent);
  124.  
  125.             printf("%.2lf do potegi %d = %.2lf\n",numberIndex, exponent, result );
  126.  
  127.             system("PAUSE");
  128.             break;
  129.         }
  130.  
  131.         default:
  132.             //printf("NaN %i \n", wyborProgramu);
  133.             break;
  134.         }
  135.  
  136.     }while (wyborProgramu != '6');
  137.  
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement