I (7) · 2019. 12. 13. · 3.141592653589793.. •double - $15 )# # % .double 64bit$)!" , */ •+!$...
Transcript of I (7) · 2019. 12. 13. · 3.141592653589793.. •double - $15 )# # % .double 64bit$)!" , */ •+!$...
��������I(7) ���
������� � ��
�������������
�����
• ��� 1126 ��
• A�A101���������
• ������ �����
5�TYr• (�U�&S-6U��eGKcET@SAc– ��X95�:Y/'*�e1JNDN@ogjfihkfSY/'��X��^SAc
• �epQo1JET@SAcm�bn
• �&e J[=Y���!e%aUCR^`<
• ;OEO?a��S^�I��e7SAc
• �H3=. e��S�&JcET@SAoLdV�>cET@ �c
"��ZTQ
5�
Y<`P367�
��qlF8e�V$cl+l#,lQ_e�dcl�V Jl4e�c
"�o�$boQ_NCWBNC
Y<`Pw561�
• �2X��eZTQV\T]M^X"�5�
��m�&X0)n
�b
H!"0�*<&�
• ,=704�/.&�printf() ��9��?�'4��-<
scanf() ��?AECEB+:�-<
• 8/1�48(;7-–��5$�G)>@3&�5��1F�)�5#�• � &�F��D��D���F��32
–�%5$�G&�?�0�<��? 6
����&'+9%A
• ��B<:;<=– B��-����(257$@>/0?*9+��(3��") (!6��+*-��
• "-��(.–����>����4��+*?–��@��– �@��,�#6��8��1#
����(1)
• ����)-&,+ ��1�� 2����#include <math.h>
•�/���� sin �0double x, y;y = sin(x);*%.(
– ��/�� x0!1��/double � float0– �#�/�� y0"1��/double � float0– x!1,'$.�/���3π0
����(")• ��������
– ���� sin(x) cos(x) tan(x)– �������� asin(x) acos(x) atan(x)– ���� exp(x) = ex– ���� log(x) = logex, log10(x) = log10x– ��� pow(x, y) = xy– � � sqrt(x) = √x– ������ fabs(x) = |x|
���!����������
#include <stdio.h>#include <math.h>
//�����&�����int main(void) {double area, radius;
printf("����������'");scanf("%lf", &area);
radius = sqrt(area / 3.14159);
printf("� %f ������ %f ��¥n", area, radius);
return 0;}
����������'5� 5.000000 ������ 1.261566 ��
#�"!�$����������%
� ��
#include <stdio.h>#include <math.h>
int main(void) {double x;int space, i;
for(x = 0; x < 3.14 * 2; x += 0.2) {space = (sin(x) + 1) * 10;for(i = 0; i < space; i++) {printf(" ");
}printf("*¥n");
}return 0;
}
**
**
*******
**
**
**
**
**
********
**
*
��� ��sin ������
����
��:>75<75��(1)
• ��� 8=6;9-��,?��-A�#��#include <stdlib.h>
•"14+��-��+�.�2&
–8=6;93��$&0�� exit(x)–��-� � abs(x)–�� rand() )'-� srand(x)+*@�,/!0#?�%"/-#�"-(��@
��8=53:53� (B)
• exit(x)�$&-6;4972��&�0
exit(0); ���� exit(1); ����>��<��+@�*6;497'�,�1"(��/��(*&@��&+ exit(0); &.�A?
• abs(x)� *��Afabs(x) '+��!%�# �Along )$�%��0 labs(x) '��*-�0A
��=?<8><8 �(C)
•��-1E��%�!/�7��,�3�)@����A
• rand() 0"�–��/( x = rand(); @9;:1��� A–�31�� 0 � RAND_MAX@�&/��A
•��-�2�6*+#'-%�"x = rand() % 6;-)4-B0, 1, 2, 3, 4, 5 0D�30.5$
�������'
#include <stdio.h>#include <stdlib.h>
int main(void) {int i;
for(i = 0; i < 10; i++) {printf("%d¥n", rand() % 6);
}return 0;
}
1152420251
1152420251
1152420251
� ����!0�5���10��"$� %� &�
•�����������#�������
��&���%!#.
• ���&�� ��&����%���"��!$%��"�����
• ����(+'*)"��!,��"-�� �#include <time.h>�����
srand((unsigned)time(NULL));
����������
#include <stdio.h>#include <stdlib.h>#include <time.h>
int main(void) {int i;
srand((unsigned)time(NULL));for(i = 0; i < 10; i++) {
printf("%d¥n", rand() % 6);}return 0;
}
4151152345
1400542155
2541202235
�������0�5����10���
�� � !�
•���������
��
• time() )�.�04H– 1970�1�1� 00:00:00C�����D(73����CUNIX�!0(E:A=;�0&'D
– +3�9������2��.8"�5%8)E�&�)#-&3/E++/4671&F
• ,72��C2038�$D– 2038�1�19�2:A=;�) 231-1 2 .8– 32@=>��*��CG3��D2��.80E�3�218à ?<8(5B &BB
��%� %�*�
•��$�� �(/"3��'double pow(double x, double y);%-�$�� �/4#����"�6
•�–�% double .�%�� double !�/
–021�% double ��%�� double !�/
–���5��/•��3��&��%���)� �/4printf , scanf &��4
double pow(double, double); "�����+�/4
���1�'�/����
• �/9<8;:/����0B
double x = 2.0, y = 3.0, z;z = sqrt(x + y);
1. x + y 7��(5 >�0 5.0 .-5?
2. �� sqrt() 7�1�(A
3. sqrt(5.0)#�&[email protected]/���#��&65A
1. �4�0 √5 = 2.2360679 .-5
4. �4�#� z .��&65
�!�'+%*&!=9<8;:0@��/��7�!)3/A�/��7�2)3/,0-!A� .��/�7��'+�� (5��'",$-!A
������� �������
a = -b;�����
���������
���https://www.grapecity.com/developer/support/powernews/column/clang/020/page05.htm
'�.> -@
• ��;CFBED<8,+,��.Ln = n + 1;
= ;'�< + =?�+;6I'�715<n = (n + 1);
7+,07:9@
• =45I��;'�<��;%?79@1. n + 1 A"�2@2. 3;��A n :��2@G��715In ;�/K�-@H
��; = 7<&+IM!#; = <(�$;�A�$;��:��2@)7+, �A��2@��G���H6*@J
+�#,$&��
• �9if(a * 2 > 10 && b * 3 < 20) { … })����)����1243%�"8
→ ((a * 2) > 10) && ((b * 3) < 20)&& )����*����-.+��)%7 �(��!0/
• �2a += 3 * -b + c;)����)����1243%�"8
→ a += ((3 * (-b)) + c) ) - *����5�)��6')%7 * -.+�������5�(��!0/6
���• ����'������ �1�+���,�1��+���,�.�),
• �3a = b * 4 / c * d;→ a = (((b * 4) / c) * d);* $ / (������#1��+��%'#1��+���-,
• �4a = b = c = 3;→ a = (b = (c = 3));����� = (�+��%'#1�+���-,2�����'�/����0(���-!� '*'%'#1�' �1a, b, c '�"& 3 ��,2
�"���/"���
• �"���/4 a # b 3��373– ��!?��?��?����10
• "���/4 #a 8 a# 3��373
– ��3�� –a 36&?a++ =a<@�8,>7"���– ���' �.$:*/<�,() 7"���sqrt(2); ��� sqrt 3�;2�(=>4 � 5�+<�,
• ��3"���?��3"���– �� -a 39%2?�2-):73– �� a++ 8 Aqrt(3) 39%2?�;2-):73
'-(,+-* ++ �)(,+-* --• ++ � -- "��#��#��$
� 1&��$.1&��/��"����0!����$
���$�0� !�&�����!��!���$
���$�0� !�&��$�!��!���$
• �
a = 1;b = a++;
a = 1;b = ++a;
a 1 &��$�!�� b ���%$!�0��!�" a � 2, b � 1 ��$
a 1 &����!�� b ���%$!�0��!�" a � 2, b # 2 ��$
� ,F���B�=5<>.D
• ���B�=@8:– �19�8��3@�"�9%9(1B�=A;!-
1
(1, 0)
(x, y) = (0, 1)
(1, 0)
(x, y) = (0, 1)
1. ���6&�2E09%B�25-/��9+�B(x,y)73@
(1, 0)
(x, y)
!", !$ = (' + 12 , +2)
2. %9��9��(cx,cy)B#�3@
(1, 0)
(x, y)
3. ��7��9$*dist B#�3@
dist = !"1 + !$1
(1, 0)
x, + = ( !"3456 ,!$3456)
4. (cx,cy)7��B�C4��7�9��B�=@
• %9(1:E(x, y) 7 (1, 0) 9)9$* l = (' − 1)1++1• �n"�B�-5�=@���9&��:E(9 ∗ ;)/2
5. �?'3
#include <stdio.h>#include <math.h>
int main(void) {int n;double x = 0, y = 1, cx, cy, dist, pi; // step 1
for(n = 8; n < 10000000; n*=2) {cx = (x + 1) / 2; // step 2cy = y / 2; // step 2dist = sqrt (cx * cx + cy * cy); // step 3x = cx / dist; // step 4y = cy / dist; // step 4pi = (sqrt((x - 1) * (x - 1) + y * y) * n) / 2;printf("%.12f¥n", pi);
}return 0;
}
����������
���
• ���3.141592653589793..
• double -��$15���)#����#�%�.double�64bit$ )!"�, */
• +!$��'�����-�*,&(0
– �����.�����/-������,
3.0614674589213.1214451522583.1365484905463.1403311569553.1412772509333.1415138011443.1415729403673.1415877252773.1415914215113.1415923455703.1415925765853.1415926343393.1415926487773.1415926523873.1415926532893.1415926535153.1415926535713.1415926535853.1415926535893.1415926535903.141592653590