Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DU03.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- char znak;
- double a[2], b[2], c[2];
- int temp1, temp2, temp3;
- void soucet(double a[2], double b[2], double c[2])
- {
- c[0] = a[0] + b[0];
- c[1] = a[1] + b[1];
- }
- void rozdil(double a[2], double b[2], double c[2])
- {
- c[0] = a[0] - b[0];
- c[1] = a[1] - b[1];
- }
- void soucin(double a[2], double b[2], double c[2])
- //soucin komplexnich cisel se vypocte realna slozka * realna slozka - imaginarni slozka * imaginarni slozka - dle vzorce (ac - bd) + i(ad + bc)
- {
- c[0] = a[0] * b[0] - a[1] * b[1];
- c[1] = a[0] * b[1] + a[1] * b[0];
- }
- void podil(double a[2], double b[2], double c[2])
- //pri podilu je treba vyloucit deleni nulou
- {
- if (b[0] == 0 && b[1] == 0)
- printf("Deleni 0 + 0j nelze.");
- else
- {
- temp1 = a[0] * b[0] + a[1] * b[1];
- temp2 = a[1] * b[0] - a[0] * b[1];
- temp3 = b[0] * b[0] + b[1] * b[1];
- if (temp1%temp3 == 0 && temp2%temp3 == 0)
- {
- if (temp2 / temp3 >= 0)
- printf("Algebraicky tvar: %d + %dj", temp1 / temp3, temp2 / temp3);
- else
- printf("Algebraicky tvar: %d %dj", temp1 / temp3, temp2 / temp3);
- }
- else if (temp1%temp3 == 0 && temp2%temp3 != 0)
- {
- if (temp2 / temp3 >= 0)
- printf("Algebraicky tvar: %d + %d/%dj", temp1 / temp3, temp2, temp3);
- else
- printf("Algebraicky tvar: %d %d/%dj", temp1 / temp3, temp2, temp3);
- }
- else if (temp1%temp3 != 0 && temp2%temp3 == 0)
- {
- if (temp2 / temp3 >= 0)
- printf("Algebraicky tvar: %d/%d + %dj", temp1, temp3, temp2 / temp3);
- else
- printf("Algebraicky tvar: %d %d/%dj", temp1, temp3, temp2 / temp3);
- }
- else
- {
- if (temp2 / temp3 >= 0)
- printf("Algebraicky tvar: %d/%d + %d/%dj", temp1, temp3, temp2, temp3);
- else
- printf("Algebraicky tvar: %d/%d %d/%dj", temp1, temp3, temp2, temp3);
- }
- }
- }
- void tisk(double c[2])
- {
- if (c[1] >= 0)
- {
- znak = '+';
- }
- else
- {
- znak = '-'; c[1] = c[1] * (-1);
- }
- printf("Algebraicky tvar: %.1lf %c %.1lfj \n", c[0], znak, c[1]);
- }
- int main()
- {
- printf("Zadej prvni realnou slozku:\n");
- scanf_s("%lf", &a[0]);
- printf("Zadej prvni imaginarni slozku:\n");
- scanf_s("%lf", &a[1]);
- printf("Zadej druhou realnou slozku:\n");
- scanf_s("%lf", &b[0]);
- printf("Zadej druhou imaginarni slozku:\n");
- scanf_s("%lf", &b[1]);
- printf("Zadej znamenko operace (+, -, *, /):\n");
- scanf_s(" %c", &znak);
- printf("\n");
- switch(znak)
- {
- case '+':
- soucet(a, b, c);
- tisk(c);
- break;
- case '-':
- rozdil(a, b, c);
- tisk(c);
- break;
- case '*':
- soucin(a, b, c);
- tisk(c);
- break;
- case '/':
- podil(a, b, c);
- break;
- default:
- printf("Zadej pouze znamenko +, -, * nebo /");
- break;
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement