17 1. strucr Potter ( ) Harry Potter and the Philosopher s Stone 1997 English Title : Harry Potter and the Philosopher s Stone : : 1997 #include<stdio.h> typedef struct Potter{ Potter; int main(void){ Potter potter1; printf("\n"); printf("\n"); printf("\n"); printf("english Title : %s\n", potter1.title); printf(" : %s\n", potter1.jptitle); printf(" : %d\n", potter1.year); return 0; 1
2. 1. 3 Harry Potter and the Philosopher s Stone 1997 Harry Potter and the Chamber of Secrets 1998 Harry Potter and the Prisoner of Azkaban 1999 English Title : Harry Potter and the Philosopher s Stone : : 1997 English Title : Harry Potter and the Chamber of Secrets : : 1998 English Title : Harry Potter and the Prisoner of Azkaban : : 1999 2
#include<stdio.h> typedef struct Potter{ Potter; int main(void){ for(i=0; i<3; i++){ printf("\n"); printf("\n"); printf("\n"); getchar(); // for(i=0 ; i<3 ; i++){ return 0; 3
3. (complex number) z = x + iy x y i i 2 = 1 z 1 = x 1 + iy 1 z 2 = x 2 + iy 2 (addition) z 1 + z 2 = z 3 z 3 = (x 1 + x 2 ) + i(y 1 + y 2 ) struct Cnum struct addcnums 2 1 cn1 2.7 5.1 cn2 3.6 8.9 cn1 = 2.7+5.1i cn2 = 3.6+8.9i cn1 + cn2 = 6.3+14.00i 2 cn1 8.2-4.3 cn2-5.4 1.9 cn1 = 8.2-4.3i cn2 = -5.4+1.9i cn1+cn2 = 2.8-2.4i 4. 3. cn1 3.5-9.4 cn2-5.6-7.1 cn1 = 3.5-9.4i cn2 = -5.6-7.1i cn1+cn2 = -2.1-16.5i 4
5. (complex number) z 1 = x 1 + iy 1 z 2 = x 2 + iy 2 (multiplication)z 1 z 2 = z 3 z 3 = (x 1 x 2 y 1 y 2 ) + i(x 1 y 2 + x 2 y 1 ) struct Cnum struct multcnums 2 1 cn1-0.5 0.86603 cn2-0.5 0.86602 cn1 = -0.50000+0.86603i cn2 = -0.50000+0.86602i cn1*cn2 = -0.50000-0.86603i 2 cn1 1 1 cn2 3-3 cn1 = 1.00000+1.00000i cn2 = 3.00000-3.00000i cn1*cn2 = 6.00000+0.00000i 6. 5. cn1 3.3 7.5 cn2-4.1 6.8 cn1 = 3.30000+7.50000i cn2 = -4.10000+6.80000i cn1*cn2 = -64.53000-8.31000i 5
7. 3 3 v1 = (v1.x, v1.y, v1.z) v2 = (v2.x, v2.y, v2.z) ( dot product) v1 v2 = v1.x v2.x + v1.y v2.y + v1.z v2.z 3 3 stuct Vector dotprod(vector v1, Vector v2) 2 1 2 7 4 2 5 1 3 vc1=(2, 7, 4) vc2=(5, 1, 3) vc1 vc2 =29 8. 7. 1 7 2 4 2 3 9 6 vc1=(7, 2, 4) vc2=(3, 9, 6) vc1 vc2 = 63 6
9. 3 v1 = (v1.x, v1.y, v1.z) v2 = (v2.x, v2.y, v2.z) ( cross product) v1 v2 = (v1.y v2.z v1.z v2.y, v1.z v2.x v1.x v2.z, v1.x v2.y v1.y v2.x) 3 3 3 stuct Vector crossprod(vector v1, Vector v1) 2 1 3 4 5 2 9 6 1 vc1=(3, 4, 5) vc2=(9, 6, 1) vc1 vc2 = (-26, 42, -18) 10. 9. 1 1 2 3 2 3 2 1 vc1=(1, 2, 3) vc2=(3, 2, 1) vc1 vc2 = (-4, 8, -4) 7
11. 3 3 stuct Vector absvalue(vector vc1) 3 (1) v = (v x, v y, v z ) v v = v 2 x + v 2 y + v 2 z (2) math.h 3 4 12 vc1=(3.000000, 4.000000, 12.000000) vc1 = 13.000000 0.5 1.2 8.4 vc1=(0.500000, 1.200000, 8.400000) vc1 = 8.500000 12. 11. 3.4 5.6 7.9 vc1=(3.400000, 5.600000, 7.900000) vc1 = 10.263040 0.8 1.5 14.4 vc1=(0.800000, 1.500000, 14.400000) vc1 = 14.500000 8
13. struct Frac addfrac(frac f1, Frac f2) 1 1/6 2 10/3 1/6+10/3=7/2 1 2/3 2 7/3 2/3+7/3=3 #include<stdio.h> typedef struct Frac{ int n; // n numerator( ) n int d; // d denominator( ) d Frac; int gcd(int n, int r){ /* */ struct Frac addfrac(frac f1, Frac f2){ /* */ int main(void){ Frac f1, f2, f3; char ch; printf(" 1 "); scanf("%d%c%d", &f1.n, &ch, &f1.d); printf(" 2 "); scanf("%d%c%d", &f2.n, &ch, &f2.d); /* */ return 0; 9
14. 13. 1 2/5 2 8/5 2/5+8/5=2 1 1/4 2 1/6 1/4+1/6=5/12 #include<stdio.h> typedef struct Frac{ int n; // n numerator( ) n int d; // d denominator( ) d Frac; int gcd(int n, int r){ /* */ void addfrac(frac *f1, Frac *f2, Frac *f3){ /* */ int main(void){ Frac f1, f2, f3; char ch; printf(" 1 "); scanf("%d%c%d", &f1.n, &ch, &f1.d); printf(" 2 "); scanf("%d%c%d", &f2.n, & ch, &f2.d); addfrac(&f1, &f2, &f3); /* */ return 0; 10
15. struct Mount 2 1625 1585 1625m 1585m 16. 2 struct swap 2 1625 1585 1625m 1585m 2 1585m 1625m 11