CS13002 Programming and Data Structures

(Autumn semester)    Section A

Assignment Set - 1

Please write your Roll Number, Name and Assignment Number at the header of each program.


Assignment 1.a:        Filename: a1a.c

(a) Write a program that reads in a number A in decimal, converts it to base-4 and prints the digits in base-4.
     The digits may be printed in reverse order, that is, with the least significant bit (LSB) first.

(b) Augment the above program to also read in a number B in octal and print it in decimal.

Hint: The following code fragment prints the decimal digits from an integer n. Which digit is printed first, LSB or MSB?

        while (n > 0)
    {
        lsb = n % 10;
        printf("%d ", lsb);
        n = n / 10;
    }


Assignment 1.b:        Filename: a1b.c

Consider the following equation:

    ( x2 - 10x + 16 )( log4 x - 2 ) = 0

Write a program that uses the bisection method (discussed in the tutorial class) to find a root of the above equation in each of the following intervals: [0, 5], [5, 10], [10, 20]

Notable Issues:

  1. Look up the library functions for computing logarithms. How can use express a logarithm of arbitrary base in terms of natural logarithms?
  2. When you use math library functions, please remember: # include <math.h> and compile with cc <file-name> -lm


Assignment 1.c:        Filename: a1c.c

A ball is thrown vertically upwards with an initial velocity of 60 km/h. Following this, the ball bounces on the ground repeatedly. The kinetic energy of the ball after each bounce becomes half of its kinetic energy before the bounce.

Write a program that computes and prints the following (assume g = 9.8 m/s2):

(a) The maximum height to which the ball rises before returning to ground in the first 10 iterations

(b) The total time spent before it hits the ground for the 10th time


Course home