Guest User

Untitled

a guest
Sep 29th, 2010
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. Exercise 1
  2.  
  3.  
  4. 1.Hello, World. Write a program that writes \Hello, World" to the screen.
  5. 2.Produce a table of Celcius and the equivalent Fahrenheit tempertures from 0 to 100
  6. 3.Write a program to sort exactly three numbers using only if-then-else statements
  7. 4.Write a program that reads in three real numbers. Determine computationally which of the following cases are true: the three numbers
  8. (a) Do not represent a triangle.
  9. (b) Represent an equilateral triangle.
  10. (c) Represent an isosceles triangle.
  11. (d) Represent a right triangle.
  12. (e) Represent a triangle that is not one of the three immediately above cases.
  13.  
  14. 5.Day of Week. A program for converting Gregorian dates in the form month-day-year to day of the week is the following. Let the Gregorian date be represented by M=D=Y where we have the following definitions
  15. M is the month of the year.
  16. Let m be the month number derived from M by the rule m is M - 2
  17. if M >= 3 and m is M + 10 otherwise.
  18. d is the day of the month.
  19. y is the year of the century.
  20. c is the number of the previous century.
  21. The algorithm is as follows:
  22. (a) A is the integer part of (13m - 1)=5.
  23. (b) B is the integer parg of y/4.
  24. (c) C is the integer part of c/4.
  25. (d) D = A + B + C + d + y - 2c.
  26. (e) Make R equal to the remainder of D/7.
  27. (f) Interpret R as Sunday if R = 0, Monday if R is 1, etc.
  28.  
  29. 6.Write a program to reverse the digits of an integer number and write the number and its reverse to the screen.
  30. 7.Check Digits. Credit cards usually have a so-called check digit. This is a single digit that is assigned when the account number is developed and has a special property. One particularly simple mechanism is to assign the last digit of the sum of all the other digits. For example, suppose we have a nine-digit account number (including the check digit). The check digit would be the sum of the eight digits. This digit could be placed anywheres in the sequence, say the third digit. As a full example, suppose the eight numbers are 12345678. Their sum is 36; thus, 6 is the check digit. The account number is therefore 126345678.
  31. Write a program to read in a nine digit integer from the keyboard and check it for
  32. these rules. Write"okay" or "not okay" for the results of the test.
  33. 8.Code the Fibonacci sequence = {1,1,2,3,5,8....}
  34. 9.Russian Peasant Multiplication. This program allows one to do multiplication by just doing muliplication or division by 2 (and addition). This is interesting since computers generally use base 2 arithmetic.The algorithm is as follows. Start two rows, one with the multiplicand (say, A) and the other the multiplier (say B). The goal is to multiply A by B. The first number is successively divided by 2 while the second number is multiplied by 2. If the number in the first column is odd, then the correspoinding number in the second column is added to the sum. The final sum is the product. Example:
  35. Multiplicand Multiplier Product
  36. 37 41 41+0 = 41
  37. 18 82
  38. 9 164 164+41 = 205
  39. 4 328
  40. 2 656
  41. 1 1312 1312+205 = 1517
  42.  
  43. 10.Write a program to determine if a given input non-negative integer is prime.
  44. 11.Sieve of Eratosthenes. Using the Sieve principle, write a program that can produce all the prime numbers greater than zero and less than or equal to some largest number Max.
  45. 12.Write a program to test whether or not an input integer has the cube property. The cube property holds for a three digit number if the sum of the cube of the digits gives the number itself. A correct number is 153= 13 + 53 + 33.
  46. 13.GCD. Write a program that finds the greatest common denominator GCD using a while loop. Write a recursive program that finds the GCD.
  47. 14.LCM. Write a program that finds the least common multiple LCM using a while loop. Write a recursive program that finds the LCM.
  48. 15.Perfect Numbers. A number P is said to be perfect if P is equal to the sum of all its factor excluding itself. Example, 28 is perfect.
  49. 16.Using the definition of perfect number, find all the perfect numbers in a range of numbers.
  50. 17.Two positive integers are friendly if each one is equal to the sum of the divisors (including one and excluding the number itself) of each other. 220 and 284 are friendly.
  51. 18.Goldbach's Conjecture. Goldbach's Conjecture is that any even number is the sum of two primes. Write a program to test Goldbach's Conjecture over a range of numbers.
  52. 19.Write a program to test the conjecture that the product of two consecutive numbers is a number between two odd numbers of which one numbers must be prime. Example: 7 * 8 = 56 and 56 is between 55 and 57. 57 is prime.
  53. 20.Consecutive Primes. Two odd numbers odd numbers that are also prime are called consecutive primes. Write a program to look for all consecutive primes in a range.
  54. 21.Pythagorean Triples. Three integers are Pythagorean triples if they satisfy the property that the square of the largest is equal to the sum of the squares of the other two numbers.
  55. 22.Palindromes. A palindrome is a number that reads the same forwards and backwards, like 12321. Write a program that tests input integers for the palindrome property.
  56. 23.Sieve of Eratosthenes. The sieve is used to find lists of prime numbers in a given interval that starts at 0. The first non-trivial prime is 2. Starting at two we proceed by removing all multiples of two from the list. The next prime, 3, is the lowest number not removed. Then all of 3's multiples are eliminated, and so on until we have found the largest prime in the interval. Write a sieve program.
  57. 24.Write a program to determine the sum of the following harmonic series for a given value of n. 1+ ½ + 1/3 + …. + 1/n
  58. 25.Write a program to read the price of an item in decimal form (like 75.95) and print the output in paise (7595 paise)
  59. 26.Write a program to convert the given temperature in Fahrenheit to Celsius using the follwing conversions formula
  60. C = ( F – 32 ) / 1.8 and display the values in tabular form
  61. 27.The straight-line method of computing the yearly depreciation of the value of an item is given by
  62. Depreciation = ( Purchase price – Salvage Value) /Years of Service
  63. Write a program to determine the salvage value of an item when the purchase price, years of service and the annual depreciation are given.
  64. 28.The distance traveled by a vehicle in t seconds is given by
  65. Distance = ut + (at)2 /2 where u is the intial velocity (metres per second), a is the acceleration ( metres per second2 ). Write a program to evaluate the distance traveled at regular intervals of time, given the values of u and a. The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of u and a.
  66. 29.In inventory management, the Economic Order Quantity for a single item is given by
  67.  
  68. EOQ =
  69.  
  70. and the optimal Time Between Orders
  71.  
  72. TBO =
  73.  
  74. Write a program to compute EOQ and TBO, given demand rate (items per unit time), setup costs (per order), and the holding cost (per item per unit time).
  75.  
  76. 30. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by
  77.  
  78. Frequency = SQRT( (1/LC) – (R2 / 4C2 ) )
  79.  
  80. 31.Write a program to find the number of and sum of all integers greater than 100 and less than 200 that are divisibly by 7.
  81. 32.A set of two linear equations with two unknowns x1 and x2 is given below:
  82. ax1 + bx2 = m
  83. cx1 + dx2 = n
  84. The set has a unique solution
  85.  
  86. x1 = (md - bn)/(ad - cb)
  87. x2 = (na - mc) / (ad - cb)
  88.  
  89. provided the denominator ad –cb is not equal to zero.
  90. Write a program that will read the values of constants a, b, c, d, m and n and compute the values of x1 and x2. An appropriate message should be printed if ad – cb = 0
  91.  
  92. 33.Given a list of marks ranging from 0 to 100, write a program to compute and print the number of students who have obtained marks
  93. a)in the range 81 to 100
  94. b)in the range 61 to 80
  95. c)in the range 41 to 60 and
  96. d)in the range 0 to 40.
  97.  
  98. The program should use a minimum number of if statements
  99.  
  100. 34.Admission to a professional course is subject to the following conditions:
  101. a) Marks in mathematics >=60
  102. b) Marks in physics >=50
  103. c) Marks in chemistry >=40
  104. d) Total in all 3 subjects >=200
  105.  
  106. or
  107. Total in mathematics and physics >= 150
  108. Given the marks in the three subjects, write a program to process the applications to list the eligible candidates
  109.  
  110. 35.A cloth showroom has announced the following seasonal discounts on purchase of items:
  111.  
  112. Purchase Amount
  113. Discount
  114.  
  115. Mill Cloth
  116. Handloom items
  117.  
  118.  
  119.  
  120. 0 - 100
  121. -
  122. 5.00%
  123.  
  124.  
  125.  
  126. 101-200
  127. 5.00%
  128. 7.50%
  129.  
  130.  
  131.  
  132. 201-300
  133. 7.50%
  134. 10.00%
  135.  
  136.  
  137.  
  138. Above 300
  139. 10.00%
  140. 15.00%
  141.  
  142. Write a program using switch and if statements to compute the net amount to be paid by a customer.
  143.  
  144. 36.Given a number, write a program using while loop to reverse the digits of the number.
Add Comment
Please, Sign In to add comment