Vaja 2 predvecer
This commit is contained in:
BIN
vaja2/a.out
Executable file
BIN
vaja2/a.out
Executable file
Binary file not shown.
84
vaja2/main.c
Normal file
84
vaja2/main.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct {double re, im;} cplx;
|
||||
|
||||
cplx csum (cplx a, cplx b) // Complex sum
|
||||
{
|
||||
cplx sum;
|
||||
sum.re = a.re + b.re;
|
||||
sum.im = a.im + b.im;
|
||||
return sum;
|
||||
}
|
||||
|
||||
cplx cdif (cplx a, cplx b) // Complex difference
|
||||
{
|
||||
cplx difference;
|
||||
difference.re = a.re - b.re;
|
||||
difference.im = a.im - b.im;
|
||||
return difference;
|
||||
}
|
||||
|
||||
cplx cprod (cplx a, cplx b) // Complex product
|
||||
{
|
||||
cplx product;
|
||||
product.re = (a.re * b.re) - (a.im * b.im);
|
||||
product.im = (a.im * b.re) + (a.re * b.im);
|
||||
return product;
|
||||
}
|
||||
|
||||
cplx cquo (cplx a, cplx b) // Complex quotient
|
||||
{
|
||||
cplx quotient;
|
||||
quotient.re = ((a.re * b.re)+(a.im * b.im)) / ((b.re*b.re)+(b.im*b.im));
|
||||
quotient.im = ((a.im * b.re)-(a.re * b.im)) / ((b.re*b.re)+(b.im*b.im));
|
||||
return quotient;
|
||||
}
|
||||
|
||||
int main(int argc, void** args)
|
||||
{
|
||||
double j, k;
|
||||
cplx a={1,2}, b={-3,-4}, c = {12.3, 12.4};
|
||||
char exitflag=0;
|
||||
int menu=0;
|
||||
while(!exitflag)
|
||||
{
|
||||
|
||||
printf("A = %.1lf%+.1lfi B = %.1lf%+.1lfi\n\n", a.re, a.im, b.re, b.im);
|
||||
puts("(1) vnos");
|
||||
puts("(2) vsota");
|
||||
puts("(3) razlika");
|
||||
puts("(4) produkt");
|
||||
puts("(5) kvocient");
|
||||
puts("(6) izhod");
|
||||
printf("Vnesi ukaz: ");
|
||||
scanf(" %d", &menu);
|
||||
switch(menu)
|
||||
{
|
||||
case 1:
|
||||
printf("Vnesi prvo vrednost: ");
|
||||
scanf("%lf%lfi", &a.re, &a.im);
|
||||
printf("Vnesi drugo vrednost: ");
|
||||
scanf("%lf%lfi", &b.re, &b.im);
|
||||
break;
|
||||
case 2: c = csum(a, b);
|
||||
printf("Vsota je %f%+fi\n",c.re, c.im);
|
||||
break;
|
||||
case 3: c = cdif(a, b);
|
||||
printf("Razlika je %f%+fi\n",c.re, c.im);
|
||||
break;
|
||||
case 4: c = cprod(a, b);
|
||||
printf("Produkt je %f%+fi\n",c.re, c.im);
|
||||
break;
|
||||
case 5: c = cquo(a, b);
|
||||
printf("Kvocient je %f%+fi\n",c.re, c.im);
|
||||
break;
|
||||
default: continue;
|
||||
case 6: exitflag++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user