Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KALKULATOR - Nzawa.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <conio.h>
- #include <stdlib.h>
- #include <math.h>>
- #define PI 3.14159265
- float dodaj(float a, float b)
- {
- float dodaj_ab = a + b;
- return dodaj_ab;
- }
- float odejmij(float a, float b)
- {
- float odejmij_ab = a - b;
- return odejmij_ab;
- }
- float pomnoz(float a, float b)
- {
- float pomnoz_ab = a * b;
- return pomnoz_ab;
- }
- float podziel(float a, float b)
- {
- float podziel_ab = a / b;
- return podziel_ab;
- }
- float podnies_do_potegi(float a, float b)
- {
- float podnies_do_potegi = pow(a, b);
- return podnies_do_potegi;
- }
- float pierwiastek(float a, float b)
- {
- float pierwiastek_ab = pow(a, 1 / b);
- return pierwiastek_ab;
- }
- float sinus(float x)
- {
- return sin(x);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- printf("Witam w programie \"KALKULATOR\" wykonanym przez: \n");
- printf("Hubert Filipiak AIR nhiestacjonarne I semestr .\n\n");
- int wybor;
- printf("Wybierz jakie dzialanie chcesz wybrac: \n");
- printf("[1]Dodawanie\n");
- printf("[2]Odejmowanie\n");
- printf("[3]Mnozenie\n");
- printf("[4]Dzielenie\n");
- printf("[5]Potegowanie\n");
- printf("[6]Pierwiastkowanie\n");
- printf("[7]Funkcja Sinus\n");
- printf("[8]Funkcja Cosinus\n");
- printf("[9]Silnia\n\n");
- printf("Napisz (cyfre) jakie dzialanie wykonac: ");
- scanf_s("%d", &wybor);
- printf("\n");
- switch (wybor)
- {
- case 1:
- float a, b, v, i, val, ret;
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = dodaj(a, b);
- printf("Wynik dodawnia to: %.2f\n", v);
- break;
- case 2:
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = odejmij(a, b);
- printf("Wynik odejmowania to: %.2f\n", v);
- break;
- case 3:
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = pomnoz(a, b);
- printf("Wynik mnozenie to: %.2f\n", v);
- break;
- case 4:
- if (b == 0)
- {
- printf("Nie dzielimy przez zero.\n");
- }
- else
- {
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = podziel(a, b);
- printf("Wynik dzielenia to: %.2f\n", v);
- }
- break;
- default:
- printf("Nie ma takiego dzialania");
- break;
- case 5:
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = podnies_do_potegi(a, b);
- printf("Wynik potegowania to: %.2f\n", v);
- break;
- case 6:
- printf("Podaj liczbe a: ");
- scanf_s("%f", &a);
- printf("Podaj liczbe b: ");
- scanf_s("%f", &b);
- v = pierwiastek (a, b);
- printf("Wynik pierwiastkowania to: %.2f\n", v);
- break;
- case 7:
- printf("Podaj kat alfa: ");
- scanf_s("%f", &a);
- val = PI / 180.0;
- ret = cos(a*val);
- printf("Sinus wynosi %lf to %lf stopni\n", a, ret);
- break;
- case 8:
- printf("Podaj kat alfa: ");
- scanf_s("%f", &a);
- val = PI / 180.0;
- ret = cos(a*val);
- printf("Coninus wynosi %lf to %lf stopni\n", a, ret);
- break;
- case 9:
- v = 1;
- printf("Podaj liczbe: ");
- scanf_s("%f", &a);
- if (a<0)
- printf("Wpisales liczbe ujemna, z ktorej nie mozna obliczyc n! \n");
- else if (a>12)
- printf("Wpisales za duza liczbe, najwieksza dopuszczalna to 12 \n");
- else
- {
- i = a;
- while (i>0)
- v *= i--;
- printf("%.2f! wynosi %.2f \n", a, v);
- }
- }
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement