-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2 answer sheet modified.txt
76 lines (59 loc) · 1.72 KB
/
p2 answer sheet modified.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//COMPLEX NUMBER
#include <stdio.h>
// Define a structure to represent a complex number
typedef struct {
double real; // The real part
double imag; // The imaginary part
} complex;
// Define a function to multiply two complex numbers
complex multiply(complex a, complex b) {
complex result;
result.real = a.real * b.real - a.imag * b.imag;
result.imag = a.real * b.imag + a.imag * b.real;
return result; // Return the result
}
// Define a function to print a complex number
void print_complex(complex c) {
// Use the format a + bi or a - bi depending on the sign of the imaginary part
if (c.imag >= 0) {
printf("%.2f + %.2fi\n", c.real, c.imag);
} else {
printf("%.2f - %.2fi\n", c.real, -c.imag);
}
}
int main() {
complex x, y, z;
printf("Enter the first complex number (real and imaginary parts): ");
scanf("%lf %lf", &x.real, &x.imag);
printf("Enter the second complex number (real and imaginary parts): ");
scanf("%lf %lf", &y.real, &y.imag);
z = multiply(x, y);
printf("The product of the two complex numbers is: ");
print_complex(z);
return 0;
}
//Pascal triangle;
#include <stdio.h>
int main()
{
int n, i, j, k;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
// Print spaces for alignment
for (k = 0; k < n - i - 1; k++)
{
printf(" ");
}
// Calculate and print the coefficients
int c = 1;
for (j = 0; j <= i; j++)
{
printf("%d ", c);
c = c * (i - j) / (j + 1);
}
// Move to the next line
printf("\n");
}
return 0;