Upload
mark-louiegi-alvarez
View
229
Download
0
Embed Size (px)
DESCRIPTION
problem set for cmsc 11
Citation preview
CMSC 11Introduction to Computer Science
Problem SetYou are not required to submit solutions to this problem set. This is means for you to assess your learning in CMSC 11 thus far.
Part 1. Device your own algorithms first in a form of flowcharts or pseudocode, before making codes before you create your codes.
Also, assume that the inputs of the user are correct.
1) Input an integer n, and print all of the divisors of n.2) Input an integer n, followed by a list of n numbers, and count the number of zeroes in the list.3) Input two positive integers a and b, and find the greatest common factor of a and b, i.e. the biggest
integer that divides both a and b exactly.4) Input two positive integers a and b, and find the least common multiple of a and b, i.e. the biggest
integer that divides both a and b exactly.5) Input three positive integers a, b and c, and find the least common multiple of a, b and c.6) Input a positive integer n, and determine whether n is prime (no divisors except one and itself) or
composite.7) Input an integer n and print the prime numbers between n and 2n.8) Twin primes are prime numbers that differ by two, i.e., 3 and 5 is the smallest pair of twin primes. Find
and print the first thirty (30) pairs of twin primes.9) Input a positive integer n, and neatly print an n ✖ n multiplication table.10) Input a positive integer n and draw an isosceles triangle-shaped figure of characters, of height n.11) Input positive integers l and w and draw a box-shaped figure l characters long and w characters thick.12) Given a user input n, which is a positive integer less than 10, generate the following number patterns. In
this example, n is equal to 5.
1234512345123451234512345
12a
5432154321543215432154321
12b
112123123412345
12c
554543543254321
12d
5 45 345 234512345
12e
12345 2345 345 45 5
12f
54321543254354554543543254321
12g
12345 2345 345 45 5 45 345 234512345
12h
1 2 3 4 5
12i
1123123451234567123456789
12j
3 2 3 41 2 3 4 5
#odd numbers#only
12k
Part 2. Determine what does these codes do. You may do a trace of the code for you to understand it.1. n = int(input("Enter n: "))
count = 1num = 1while count <= n: num = num * i print(num) count = count + 1
2. n = int(input("Enter n: "))a = 0b = 1
for i in range(0, n): a = b b = a + bprint(a)
3. n = int(input("Enter n: "))a = 1b = 1old = 0for i in range(1, n): old = a a = b b = old + b if(a % 2 == 1): print("Odd") else: print("Even")