This action might not be possible to undo. Are you sure you want to continue?

LAB: 06

**Sukkur Institute of Business Administration
**

Introduction to Programming

Lab: 06

1. Determine the value of the following expressions, assuming a = 5, b = 2, c = 4, d= 6, and e= 3 (Do it manually): (a) a > b (b) a != b (c) d % b==c % b (d) a*c!=d*b (e) d*b==c*e (f) !(a * b) (g) !(a % b*c) (h) !(c % b*a) (i) b % c*a 2. Using parentheses, rewrite the following expressions to indicate their order of evaluation correctly. Then evaluate each expression, assuming a = 5, b = 2, and c = 4. (a) a % b * c && c % b * a (b) a%b ∗ c||c%b ∗ a (c) b % c*a && a % c*b (d) b%c ∗ a||a%c ∗ b 3. Write C++ code sections to make the following decisions: (a) Ask for two integer temperatures. If their values are equal, display the temperature; otherwise, do nothing. (b) Ask for character values letter1 and letter2, representing uppercase letters of the alphabet, and display them in alphabetical order. (c) Ask for three integer values, num1,num2 , and num3, and display them in decreasing order. 4. (Probability) The probability that a telephone call will last less than t minutes can be approximated by the exponential probability function: Probability that a call lasts less than t minutes = 1 − e−t/a a is the average call length. e is Eulers number (2.71828). For example, assuming the average call length is 2 minutes, the probability that a call will last less than 1 minute is calculated as 1 − e−1/2 = 0.3297. Using this probability equation, write a C++ program that calculates and displays a list of probabilities of a call lasting less than 1 minute to less than 10 minutes, in 1-minute increments.

1

Using suitable repetition structure generate a ﬁbonacci series up to n terms. 3. . and test a C++ program that ﬁnds and prints all the prime numbers less than 100. You may need to use nested loop(s). 1. 5. run. Using this information. 9. The output of your program should appear as given. where n ranges from 2 to sqrt(number). For each number from 2 to 100. and test a C++ program that displays how much the king must pay the beggar on each day. the ﬁrst two terms are 0 and 1.000. namely 1 and the number itself. and each term thereafter is the sum of the two previous terms that is. 2. For example.) 8. The Fibonacci sequence is 0. ﬁnd Remainder = Number % n. Using this information. An old Arabian legend has it that a fabulously wealthy but unthinking king agreed to give a beggar one cent and double the amount for 64 days. the number is not equally divisible by n. where the user enters n into the program interactively. Write. the number is not a prime number. your program should give: 0 1 1 2 3 5 8 13 7. Why? If any Remainder equals 0. user wants to generate ﬁrst 8 ﬁbonacci terms so. 1. your program should determine on which day the king will have paid the beggar a total of one million(1. Modify the Fibonacci sequence program in the previous question so that now it should ask the user how many ﬁbonacci terms n to generate. the program should display the value 5. 2 . write. 8. . 13. Write a program Triangle. Also. For example. Fib[n] = Fib[n . .000) dollars. run. 6. if n = 6. (Hint: 1 is a prime number.1] + Fib[n .java that takes an integer N and prints an N x N triangular pattern like the one below. If n is greater than sqrt(number). write a C++ program that calculates the nth number in a Fibonacci sequence.2].Spring 2012 Nahdia Majeed LAB: 06 5. A prime integer number is one that has exactly two diﬀerent divisors. .

Write a program Ex.java that takes an input N and prints a (2N + 1) x (2N + 1) ex(X) like the one below. 3 .Spring 2012 Nahdia Majeed LAB: 06 10. Write a program Diamond. Use two for-loops and one if-else statement.java that takes an input N and prints a (2N +1)x(2N +1) bowtie like the one below.java that takes an input N and prints a (2N +1)x(2N +1) diamond like the one below. 12. Use two for-loops and one if-else statement. 11. Write a program BowTie.

Sign up to vote on this title

UsefulNot useful- Twin Prime Conjecture
- Magic Squares
- homework-01.pdf
- s-problems
- Bilangan Fibonacci
- On a Smarandache problem concerning the prime gaps
- Elementary Number Theory and Methods of Proof
- Russo
- Maths Primes
- Problem Set Asia Cup
- PRIME NUMBERS AS POTENTIAL PSEUDO-RANDOM CODE FOR GPS SIGNALS
- As1.pdf c+2
- Number Theory
- Contoh Soal Simulasi ACM-ICPC
- PDFs Week6Lecture5
- Soal_Simulasi_Kompetisi_ACM-ICPC.pdf
- a1
- Erdős–Kac theorem
- Prime Divisible
- Phi Tau Sigma
- Number Theory
- Euclid’s Element Book 9
- Science Aurora 2005
- Apt i 3 Solutions
- JEE Questions Probability
- MODULE 6- cal Reasoing
- Prob for EE - Tut 2
- SSLC maths paper
- Crystal Report Designer Component in VC++
- ch03[1]
- ICP Lab-06