Write a program to to calculate string palindrome.
Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
Sunday, August 24, 2014
Tuesday, August 5, 2014
Monday, August 4, 2014
Count number of bits are set to 1
Write a program to count number of bits are set to 1 in an integer.
Calculate daily expenditure if monthly expenditure is given
Write a program to calculate daily expenditure if monthly expenditure is given using loop.
Thursday, October 10, 2013
Service counter
Consider a service counter. People waiting for service form a queue. At the start, the queue is empty and time is 0. The service time per person is 3 minutes. The input to the program consists of an integer N followed by a sequence of integers indicating the arrival time (in minutes) of the customers. These times are given as offset from the start of the simulation, so that an input of 44 means 44 minutes from the start of simulation.
Boolean OR of Two Digital Signals
Write a program to generate a boolean OR of two digital signals. A signal has two states, a high state and a low state. It is given as an array of positive integers in ascending order. Each pair of integer indicates the range of the signal in a high state. The array size will be even, so that the signal starts with a low state and ends with a low state.
Tuesday, October 8, 2013
Manipulate linked lists
Write a program in C to manipulate linked lists. The input to the program will be a sequence of instructions of the following three categories:
The list should always be maintained in sorted order in increasing order of age. If there is more than one person of same age, the order should be as in the input. You may assume that the input is valid and correct. While executing remove or print, if the list does not have enough elements, the command should be
ignored.
You may assume that the name is always a single word with no spaces within. The age will be a positive integer. Terminate each line output with a newline character.
- insert name age: create a node with item as the info field and insert into the current list.
- remove N : remove the Nth item from the list.
- print N : print the Nth item from the list. The name should be printed first and then the age with a space in between.
- stop : end of instructions
The list should always be maintained in sorted order in increasing order of age. If there is more than one person of same age, the order should be as in the input. You may assume that the input is valid and correct. While executing remove or print, if the list does not have enough elements, the command should be
ignored.
You may assume that the name is always a single word with no spaces within. The age will be a positive integer. Terminate each line output with a newline character.
Monday, October 7, 2013
Sunday, October 6, 2013
Horizontal/Vertical Line Crossings
Archeologists have discovered a very ancient cave, with many pictures on its wall. Each of the picture contains only vertical and horizontal line segments. Experts have analysed these pictures and came to the conclusion that, these are hieroglyphs (like Egyptian writings). To extract the meaning from these glyphs, it is necessary to find out how many of these vertical and horizontal line segments intersect.
Each picture glyph is inscribed in a square of side 100, and each end point of the line segment is assigned an X-Y coordinate pair. All the X and Y values are integers in the range 0 to 100. The vertical line segment is described by an X value and two Y values (X, Y1, Y2). Similarly, a horizontal line segment is described by a Y value and a pair of X values (Y, X1, X2). For example, a horizontal line segment described by a triplet (12, 8, 57) is a segment joining points (8, 12) and (57, 12).
You have to write a program to compute the total number of intersections, given the details of vertical and horizontal line segments. Only the intersections between a pair of horizontal and vertical line segments are counted. Even if one segment is touching another, it is counted as an intersection. (See figure below)
Saturday, October 5, 2013
Removal of ‘Zero’ Rows and Columns in a Matrix
Given an integer matrix of size, say, M x N, you have to write a program to remove all the rows and columns consisting of all zeros. Your program must remove those rows and columns that consist of zero valued elements only. That is, if all the elements in a row (column) are zeros, then remove that row (column). All the remaining rows and columns should be output.
Input Specification:
- The first line of input will have two integers, say, M and N. M specifies the number of rows in the matrix and N specifies the number of columns in the matrix.
- This will be followed by M lines, each consisting of N integers.
Note: Assume 1 ≤ M ≤ 10 and 1 ≤ N ≤ 10. Also, you may assume that there is at least one nonzero element in the given matrix.
Subscribe to:
Posts (Atom)

