Coding Paradise. Learn. Ask. Code. REPEAT.

Monday 24 August 2015

Selection sort using C language

PROBLEM STATEMENT

SELECTION SORT


Write a C program to perform selection sort on an array of n elements.
Selection sort algorithm starts by comparing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:

Print result after every Iteration.

Sunday 23 August 2015

Implementation of Binary Search in C

PROBLEM STATEMENT

Write a C program to implement Binary Search Algorithm.
Include a function
int BinarySearch (int, int, int *, int x) --- The 1st parameter is the lower limit of the list or array, the 2nd parameter is the upper limit of the list or array, the third parameter is a pointer to the array and the fourth parameter is the search element.
Please note that the index of the search element is returned by the function. If the search element is not present in the array, -1 is returned.
Assume that the maximum size of the array is 10 . Please note that if a is the array, then a[0] is in position 0, a[1] is in position 1 ...

'Library fine' from Hackerrank solution in C language

Problem Statement
The Head Librarian at a library wants you to make a program that calculates the fine for returning the book after the return date. You are given the actual and the expected return dates. Calculate the fine as follows:
  1. If the book is returned on or before the expected return date, no fine will be charged, in other words fine is 0.
  2. If the book is returned in the same month as the expected return date, Fine = 15 Hackos × Number of late days
  3. If the book is not returned in the same month but in the same year as the expected return date, Fine = 500 Hackos × Number of late months
  4. If the book is not returned in the same year, the fine is fixed at 10000 Hackos.
Input Format
You are given the actual and the expected return dates in D M Y format respectively. There are two lines of input. The first line contains the D M Y values for the actual return date and the next line contains the D M Y values for the expected return date.

Saturday 22 August 2015

Searching element in an array : C


PROBLEM STATEMENT

Searching an Array
Write a C program to search for an element ‘a’ in the array. (Linear Search)
Input Format:
Input consists of n+2 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the array. The last integer corresponds to ‘a’, the element to be searched.
Assume that the maximum size of the array is 20.
Output Format:
Refer  sample output for details.

Popular Posts

Powered by Blogger.