1
play

$ - PDF document

1/27/2010 2 ) !!(!(%#' 78 ( 9 ((%:


  1. 1/27/2010 ��2� ���������) !!�(����!(����%�#��' � �������7�8 ��� ( 9� ��� �(���(%: � �������)�!����������������*����( 9��!����/�(��-�!� �%,��)��/��.�!�(�������%��# �$�����,��� /�� � ���� /� ��; ��!��"� ����2 �#�������) �$�� /(�( �� � �((�%� �) "������(������6������ � ��������"�����%�#���$��)�#��,�)�"�� � � ������� ��,( "�%<������,�(0�=>�����#��)�%�%������,� ������������� $� �$������������#�+����,�(������"�,%��!�������1 ��������������������� � ?��)�#��+ �%� �� �)���(%1��5�(%�"�����1 ������������������������� ������!���"#����$% &#��� ��������' ���,���"��,�( ����"�)� � �(�$(��� �$����$��$����) � �#��! (���,(�$(���2�����0�)���� ����2�����,( ���(���� ��/���!��"� ��1�����@�������#���%���9� �������/1 � ����$(���)�*�+���,�������+ (�������-�*�. � ��)��/%��#�����#&�(0����"1 � ��+ �2�"�)�� ������)��%�#���! (�� � ����#�2��������2���)�"�)���#��(������/���,(�/��� from math import * ��(������ ��2� ���������� � ��(�����%�#��' def printRootTable (n): �9��,���� for i in range(1,n): ���%�#��� print " %2d %7.3f" % (i, sqrt(i)) � � � ��(�����*��� ��)��1 def main (): printRootTable(10) � ����(�"� +����)��!�(�3� "0������ main() � �(�$(��� �$���)��!�(�2( � �$�"�)� #include <stdio.h> � �%�#���#���1,%�! ����!�(�"�)� #include <math.h> � ������������1��! ����!�(�"�)� void printRootTable( int n) { int i; for (i=1; i<=n; i++) { � � � ��(�,(�$(��� �$�"��"�,�������%�#��4 printf(" %2d %7.3f\n", i, sqrt(i)); } � 5�( �/���6�!��"� ���6� !6�!�(6�2# ��6���"1 } int main() { printRootTable(10); return 0; } 1

  2. 1/27/2010 (�����/��� �������� 2# ������,� % for comments 0�7��� First set of them used as the 2# ���-0C�. help message 070;� Functions ��) � � ��(�����#�� !����������� For loops; try typing 1:10 ������ ��������#��:/(��0B���������������9 ����(�%� !� ���)�) Familiar? !���������� !�(����,� ������������������������ !�(� 7�����1�������� !�-�A�.� D�)�����!! 9�7�� ��) ��) ���,�(�����(��$�� ���%�#��� !�(� ��(��$�-�6��6�1���.��-2# "#�)����@��2�(0. E)�����!! �����#�+�����:��)B���������� �������!�(����,6��0�7�! (����� �"(������������� ��// �$� ��!�(����0�����% -"���)��� �� �"(���������)�!���������6�� 0���%�#��. -.��(���)�"��) � �� Your turn: Program now: code to print multiples of 5 up to 50. Then print only those not divisible by 3. �� !���������� ���"� ���� �������� !�-�A�. 97� ���� !-�C�. 97� ����� 97� ��) ���%����(���(������ ,���+�����6����:(���(�B����������� ���)�) ����(����! (���!��"� ��6�2# "#��#���)�#�+������������ �� !� ��)����������� !�-����2�(). ���1��! �� 2

  3. 1/27/2010 ��,������)����,�����(���,� ���� !�"��( ����/�� ���,�� � !��"� �� �������"� �� � ���� �$�!�"��( ����/�� �#���)�,(�)�"���# �����,��� � ��� �,�����(����,��� 1! = 1 � !��"� �� F9G�7��������"� ��� 2! = 2 � ���%������,���"����)�9 3! = 6 4! = 24 � !��"� �� �������"� ���-�. 5! = 120 � ���%��� �,���"����)�� 6! = 720 7! = 5040 � !��"� �� F%G�7��������"� ��H-�6/6". 8! = 40320 � �� �,�����6�/6�"���)������,���% 9! = 362880 10! = 3628800 �!��#��,( ��(%�!��"� ���#��� �,���6�"����!(���"�����)�� ��6� >> �!���� �,�������)�)6�%���"�������"������-�(��>. ��������"( ,���+���������!��"� ��� *�/�$$�( � ��������"( ,�� � ����# ��"���6�������� ����(��� 0���"� ,����#����*�� � ���!��"� �� � $����(��� ��6�I����"�)� � �������#���������%��������)�/�$$�( � ����+�( �/����+ � /��� ��2�(0�,�"� � �����/!��"� ��� ������< � �))���/(��0,� �������#�����(���!�%��(�!�"��( ����/�� � �������!��"� ��� "�)��-! (���� ��� ���#��!�"��( ����/�� !��"� ��. � � (���� ����!�"�)�� �����!��"� ���F���,���G�7������- �,���. � ���,� �����#��"�)��/%�(��� �$�!��"� ��� ���#��� � ��/!��"� ��� -#��,�(�!��"� ���.�����2�)� �������1��! �� � �,����#��&�(0�,�"��2 �)�2�-�,,�(���!����/.���� � 5�( �/����"�,��� � ��)����!��"� �� ����+����� � ��+ � ���9��,�������!�(�������1 ���)������������!��"� ���1��! ��� ����3� "0�0�%�J�#�(�"����-���#��)���. � �����!��#��! (���!��"� ����2����)�� ���%�#���2����� � ?,��((�2 ; ����(�"� +����)��������)�� ���(% !�"��( ���!��"� ��1 � ��������� ����� ; ��(��0 � ��0����,(�$(����#���#��������! ���"����)� � ?�"�������� �� ; ��(��� :!�"��( ����/��1�B � ����"�����J�������)��� ; ��(��������(��� � ��0������/!��"� �� "����)�"��"�������"��( ��-�.��#��� � ����1��! �� ; �> (���(����#���<�+���������#��!�"��( ����/�� !��"� �� � ����"��,���� ; ��/ � ��� �����#��,�����#����/!��"� ������� � ��+� ; ��(��� !��"� ���F(�����G�7�"��"�������"��( ��-�. � ����)�()�"�,%6�"��6�,���� (������7�� 4 Example output on next slide: 3

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend