Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise 1
- 1.Hello, World. Write a program that writes \Hello, World" to the screen.
- 2.Produce a table of Celcius and the equivalent Fahrenheit tempertures from 0 to 100
- 3.Write a program to sort exactly three numbers using only if-then-else statements
- 4.Write a program that reads in three real numbers. Determine computationally which of the following cases are true: the three numbers
- (a) Do not represent a triangle.
- (b) Represent an equilateral triangle.
- (c) Represent an isosceles triangle.
- (d) Represent a right triangle.
- (e) Represent a triangle that is not one of the three immediately above cases.
- 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
- M is the month of the year.
- Let m be the month number derived from M by the rule m is M - 2
- if M >= 3 and m is M + 10 otherwise.
- d is the day of the month.
- y is the year of the century.
- c is the number of the previous century.
- The algorithm is as follows:
- (a) A is the integer part of (13m - 1)=5.
- (b) B is the integer parg of y/4.
- (c) C is the integer part of c/4.
- (d) D = A + B + C + d + y - 2c.
- (e) Make R equal to the remainder of D/7.
- (f) Interpret R as Sunday if R = 0, Monday if R is 1, etc.
- 6.Write a program to reverse the digits of an integer number and write the number and its reverse to the screen.
- 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.
- Write a program to read in a nine digit integer from the keyboard and check it for
- these rules. Write"okay" or "not okay" for the results of the test.
- 8.Code the Fibonacci sequence = {1,1,2,3,5,8....}
- 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:
- Multiplicand Multiplier Product
- 37 41 41+0 = 41
- 18 82
- 9 164 164+41 = 205
- 4 328
- 2 656
- 1 1312 1312+205 = 1517
- 10.Write a program to determine if a given input non-negative integer is prime.
- 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.
- 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.
- 13.GCD. Write a program that finds the greatest common denominator GCD using a while loop. Write a recursive program that finds the GCD.
- 14.LCM. Write a program that finds the least common multiple LCM using a while loop. Write a recursive program that finds the LCM.
- 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.
- 16.Using the definition of perfect number, find all the perfect numbers in a range of numbers.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 24.Write a program to determine the sum of the following harmonic series for a given value of n. 1+ ½ + 1/3 + …. + 1/n
- 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)
- 26.Write a program to convert the given temperature in Fahrenheit to Celsius using the follwing conversions formula
- C = ( F – 32 ) / 1.8 and display the values in tabular form
- 27.The straight-line method of computing the yearly depreciation of the value of an item is given by
- Depreciation = ( Purchase price – Salvage Value) /Years of Service
- Write a program to determine the salvage value of an item when the purchase price, years of service and the annual depreciation are given.
- 28.The distance traveled by a vehicle in t seconds is given by
- 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.
- 29.In inventory management, the Economic Order Quantity for a single item is given by
- EOQ =
- and the optimal Time Between Orders
- TBO =
- 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).
- 30. For a certain electrical circuit with an inductance L and resistance R, the damped natural frequency is given by
- Frequency = SQRT( (1/LC) – (R2 / 4C2 ) )
- 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.
- 32.A set of two linear equations with two unknowns x1 and x2 is given below:
- ax1 + bx2 = m
- cx1 + dx2 = n
- The set has a unique solution
- x1 = (md - bn)/(ad - cb)
- x2 = (na - mc) / (ad - cb)
- provided the denominator ad –cb is not equal to zero.
- 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
- 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
- a)in the range 81 to 100
- b)in the range 61 to 80
- c)in the range 41 to 60 and
- d)in the range 0 to 40.
- The program should use a minimum number of if statements
- 34.Admission to a professional course is subject to the following conditions:
- a) Marks in mathematics >=60
- b) Marks in physics >=50
- c) Marks in chemistry >=40
- d) Total in all 3 subjects >=200
- or
- Total in mathematics and physics >= 150
- Given the marks in the three subjects, write a program to process the applications to list the eligible candidates
- 35.A cloth showroom has announced the following seasonal discounts on purchase of items:
- Purchase Amount
- Discount
- Mill Cloth
- Handloom items
- 0 - 100
- -
- 5.00%
- 101-200
- 5.00%
- 7.50%
- 201-300
- 7.50%
- 10.00%
- Above 300
- 10.00%
- 15.00%
- Write a program using switch and if statements to compute the net amount to be paid by a customer.
- 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