COSC 117 Lab 2 - Salisbury University

COSC 117 Lab 2 - Salisbury University

COSC 117 LAB 2 Dr. Joe Anderson September 6, 2017 MODULUS OPERATOR Modulus operator: % Performs division of two numbers and returns only the remainder Ex: 11 % 5 == 1

10 % 5 == 0 23 % 3 == 2 Common usage: to test if a number is even or odd! If n is even, then n % 2 == 0 If n is odd, then n % 2 == 1 LAB: 3N + 1 PROBLEM Given: a positive integer n If n is even, divide it by 2

If n is odd, multiply it by 3 and add 1 Stop when n is 1, otherwise, repeat Ex: Start with 3 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 Your tasks: Ask user for a positive int Perform 3N + 1 operation, until it reaches 1, and print each step to the terminal

Recently Viewed Presentations

  • Multicultural Counseling: The Factors, the Theories and ...

    Multicultural Counseling: The Factors, the Theories and ...

    Social justice-scholarship and professional action designed to change societal values, structures, policies, and practices, such that disadvantaged or marginalized groups gain increased access to… tools of self determination." (Steele, J.M., 2008) Advocacy - taking action to produce environmental change on...
  • Presentation - T-Coffee

    Presentation - T-Coffee

    The Triplet Assumption SEQ A SEQ B Weighting And Extension Extension=Using Information from Other Sequences Weighting=Using The surrounding Information (Coffee) T-Coffee Progressive Alignment Notredame, Higgins, Heringa, 2000 Dynamic Programming Using The extended Library Local Alignment Global Alignment Extension Multiple Sequence...
  • Unit 10 Comparing North and South - Central Dauphin School ...

    Unit 10 Comparing North and South - Central Dauphin School ...

    View of the famous levee of New Orleans, the capital of Louisiana, which commencing 43 miles below passes through the [c]ity forming its chief business depot, and extends 143 miles above, on the banks of the Mississippi / photographed by...
  • Affordable Care Act: Implications for School Systems

    Affordable Care Act: Implications for School Systems

    "The longer I live, the more I realize the impact of attitude on life. Attitude, to me, is more important than facts. It is more important than the past, than education, than money, than circumstances, than failures, than successes, than...
  • Using a Medical Dictionary - Wasatch

    Using a Medical Dictionary - Wasatch

    Using a Medical Dictionary Medical Terminology Utah State Office of Education Utah State Office of Education Using A Medical Dictionary Even with the best deciphering skills, your analysis of an unfamiliar term can sometimes produce a strange-sounding definition.
  • Fever, 1793 - Chapters 1-3

    Fever, 1793 - Chapters 1-3

    Fever 1793Chapters 1-3. What type of business does Matilda's family own? Why does Eliza think Philadelphia is the best place to be a freed slave? Why does Mattie think Eliza is the luckiest person she knows and considers her to...
  • The Church of Christ

    The Church of Christ

    Examples Of Authoritative Examples. Acts 14:23 - When they had appointed elders for them in every church, having prayed with fasting, they commended them to the Lord in whom they had believed. Acts 20:28 - Be on guard for yourselves...
  • Québec & Canada - Ms Martin's History 30

    Québec & Canada - Ms Martin's History 30

    THE FLQ. Since 1963, the FLQ had exploded several bombs, which killed six people. While mailboxes, particularly in the affluent and mostly English section of Montreal, Westmount, were common targets, the largest single bombing was of the Montreal Stock Exchange...