Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "my_header.h"
- int main()
- {
- do
- {
- printf("Kalkulator\n\nWybierz jedna z opcji\n\n");
- puts("1 Dodawanie");
- puts("2 Odejmowianie");
- puts("3 Mnozenie");
- puts("4 Dzielenie");
- puts("5 Potegowanie");
- puts("6 Zakoncz program");
- scanf("%c", &wyborProgramu);
- system("CLS");
- switch (wyborProgramu)
- {
- case '1':
- {
- printf("Ile liczb chcesz dodac?\n");
- scanf("%d", &iloscLiczb);
- arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double)); /* alokacja pamieci*/
- enterNumbers(arrayOfNumbers, iloscLiczb); /* Przyjowanie liczb do tablicy*/
- result = adding(arrayOfNumbers, iloscLiczb); /*Dodawanie*/
- writingOut(arrayOfNumbers, iloscLiczb, '+'); /*Wyświetlenie wyniku*/
- free(arrayOfNumbers);
- result = 0;
- iloscLiczb = 0;
- system("PAUSE");
- break;
- }
- case '2':
- {
- printf("Ile liczb chcesz odjac?\n");
- scanf("%d", &iloscLiczb);
- arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
- enterNumbers(arrayOfNumbers, iloscLiczb);
- result = subtraction(arrayOfNumbers, iloscLiczb);
- writingOut(arrayOfNumbers, iloscLiczb, '-');
- free(arrayOfNumbers);
- result = 0;
- iloscLiczb = 0;
- system("pause");
- break;
- }
- case '3':
- {
- printf("Ile liczb chcesz pomnozyc?\n");
- scanf("%d", &iloscLiczb);
- arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
- enterNumbers(arrayOfNumbers, iloscLiczb);
- result = multiplication(arrayOfNumbers, iloscLiczb);
- writingOut(arrayOfNumbers, iloscLiczb, '*');
- free(arrayOfNumbers);
- result = 0;
- iloscLiczb = 0;
- system("pause");
- break;
- }
- case '4':
- {
- printf("Ile liczb chcesz podzielic?\n");
- scanf("%d", &iloscLiczb);
- arrayOfNumbers = (double*)malloc(iloscLiczb * sizeof (double));
- enterNumbers(arrayOfNumbers, iloscLiczb);
- for(int i = 0; i < iloscLiczb; i++)
- {
- if(arrayOfNumbers[i] == 0.0)
- {
- printf("Nie dzieli sie przez 0\n");
- exit(1);
- }
- }
- result = division(arrayOfNumbers, iloscLiczb);
- writingOut(arrayOfNumbers, iloscLiczb, '/');
- free(arrayOfNumbers);
- result = 0;
- iloscLiczb = 0;
- system("pause");
- break;
- }
- case '5':
- {
- printf("Podaj podstawe: \n");
- scanf("%lf", &numberIndex);
- printf("Podaj wykladnik: \n");
- scanf("%d", &exponent);
- result = exponentiation(numberIndex, exponent);
- printf("%.2lf do potegi %d = %.2lf\n",numberIndex, exponent, result );
- system("PAUSE");
- break;
- }
- default:
- //printf("NaN %i \n", wyborProgramu);
- break;
- }
- }while (wyborProgramu != '6');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement