Вы находитесь на странице: 1из 6

Question bank for the programming contest (I-Know-vention on 26th Jan 2012) There are problems of graded complexity.

In the contest each of you will get a mix of easy and difficult problems to solve. The problems you will get will be from this question bank only. You are expected to solve all the questions using the next two days and secure your place in the final round. Wish you all the best! 1. A variable can be declared many times, defined once. (True / False) 2. extern is declaration / definition / initialization. (Multiple choice) 3. initialization takes care of declaration / definition / both / none of these. (Multiple choice) 4. It is possible to use extern at the page that holds definition of the extern variable? (True / False) 5. How to find whether end-of-file has been reached? 6. Write a program to copy its input to its output replacing each tab by the string Tab, white space by Blank and backslash by BackSlash. In case of successive tabs or blanks or backslashes, the output should be appropriately designed. For example, occurrence \\\ should be replaced by 3 blackslashes. 7. {kamal, vimal, asmaa, aaditya, abdul, kshitij, mary, amrit, sanjeevan, pritha, kiran} is a set of names of my classmates. Write a program that takes a name and tells if the person is my classmate or not. In any case, your search should not involve more than one comparison. 8. (kamal, vimal, asmaa, aaditya, abdul, kshitij, mary, amrit, sanjeevan, pritha, kiran) is a list of names of my classmates. Write a program that reads a letter and displays all the names that are starting with that letter. Remember, if the original list has n elements and the last name starting with the given letter is at the i-th position, your look-up should not involve traversing the remaining n-i names. 9. Write a program that generates a random number of given length. 10. Write a program that reads a line and aligns the text to both the right and left margins by adding spaces between the words as necessary. 11. Write a program that plots a graph of word-length vs. frequency of the words of the specific length in the given text. 12. Write a program that prints a histogram of frequencies of different characters in its input. 13. Write a program that computes b(n/d) where b, n and d are integers. 14. Given: A line comprised of one or more words that are separated by a space or a tab. End of a line is denoted by an EOF symbol. (Assume: a word is a string of one or more letters, and letters are lower-case, i.e., belong to the set {a, b, c, ..., z}. ) Write a program that reads a

text file and converts it to a sequence of lines as per the definition above. If the length of a line exceeds 80 characters, introduce one blank line after printing the same it. 15. Suppose there is some text containing words spread out over a few lines. You are given a table with two columns: line number and number of words in the line. Write a program that partitions the given table into sub-tables such that in each of the sub-tables the records will be in ascending order of the line numbers as well as the line-lengths (number of words in the line).You are supposed to read each record in the original table only once and decide its place in the new data structure of sub-tables. Example: Given Line No. L1 L2 L3 L4 L5 L6 L7 L8 L9 L10 L11 L12 L13 L14 L15 L16 L17 Word count 3 4 2 3 2 4 2 2 3 4 2 8 5 6 5 7 7 Line No. L1 L2 L6 L10 L12 = Word count 3 4 4 4 8 + Line No. L3 L4 L9 L13 L14 L16 L17 Word count 2 3 3 5 6 7 7 Line No. L5 L7 L8 L11 L15 + Word count 2 2 2 2 5

16. Write a program called reverse_input for the following behaviour: (1) If the input is a single word, then the output has the word in reverse order, i.e., the last letter of the input word will become the first letter of the output string, the second-last input letter becomes the second output letter and so on. (2) If the input is a single line with several words, then the output has the words in reverse order (but the letters in the words are not reversed). (3) If the input has several lines, then the output has the lines in reverse order (without changing the order of the words in each line). 17. Write a program to fold the given very long lines into shorter lines that fit to a given page width constraint. Your program must do something intelligent if there are very long words and no space or tab are found near the place where you decide to cut the line to fit it to the page width. It should to create an "almost-justified" effect, in an attempt to touch both right as well as left margins.

18. Write a program that checks a C program for rudimentary syntax errors like mismatched brackets, parenthesis, braces, quotes and comments. 19. Write a program to generate all possible bit-strings of length n where n is a positive integer. (Note: The faster the program, the greater the credit.) 20. Write a program to generate all strings of length upto k on a given set of symbols. (Hint: Take 26 symbols in the lower-case English alphabet {a, b,c, ..., z} and k = 3; print the first 100 strings of your output sorted by length.) 21. Write a program to generate all strings of length upto k on a given set of symbols. (Hint: Take 26 symbols in English alphabet = {a, b,c, ..., z} and k = 3; print first 100 strings of your output sorted in dictionary order) 22. Write a program to generate all strings of length upto k on a given set of symbols. No symbol should be repeated in any string. (Hint: Take the 26 lower-case symbols in the English alphabet {a, b,c, ..., z} and k = 3; print the first 100 strings of your output sorted in dictionary order) 23. Write a program to compute the index of a given letter-string in a list that has all strings of length upto k generated over n symbols and sorted length-wise. (Hint: Take the 26 lowercase symbols in the English alphabet {a, b,c, ..., z} and k = 3; print the index of the strings aaa, aab, abb and bbb.) 24. Write a program to compute the index of a given letter-string in a list that has all strings of length upto k generated over n symbols and sorted in dictionary order. (Hint: Take the 26 symbols in English alphabet {a, b,c, ..., z} and k = 3; print the index of the strings aaa, aab, abb and bbb) 25. Implement the tries data structure to store strings of arbitrary length generated over the English alphabet. Say for example, I want to store names of my friends (hiranmayi, rama, vimal, asmaa, aaditya, sanjeevan, abdul, kshitij, mary, rit, prithviraj). Test your program for any 5 successive keys in the given list. 26. Given m different routes between n cities, where m and n are integers, and 2 new cities that are connected with all n cities, write a program to find the shortest route that connects all n+2 cities. 27. Write a program to test whether the given number is prime. Remember the faster the program, the higher the credits 28. Write a program for an intelligent editor which suggests possible longer word after you typing 3 letters of any word and hence saves your efforts just by letting you the selection instead of the typing the whole. 29. Write a program to find Pythagorean triplet in the range 0 to 100 30. Write two functions namely SumDigitsRecurssively and SumDigitIteratively that calculate sum of the digits of a given number. Test your functions by calling them in main().

31.Write a function MySqrt that takes one number and computes its squre root. 32. Write a program to generate following triangle by reading input level = 3 11 2112 321123 (Hint: Your program should generate the first two lines of this display if level = 2. It should display k lines to form the pyramid of k levels for input level = k) 33. Write a program, which scrolls Hi on the screen from left to right and Hello on the screen from right to left and when both meet in the centre it displays Bye 34. Simulate stack using pointers. Use malloc function. 35. Write two functions FibonacciRecurssively and FibonacciIteratively. Test your functions by calling them in your main. 36. Write a program to compute sine of a given angle by using the following formula.

37. Write a program for matchstick game between the computer and a user. Your program should ensure that computer always wins. Rules for the game are as follows: R1: There are 21 matchsticks R2: The computer asks the player to pick 1, 2, 3 or 4 matchsticks R3: After the person picks, the computer plays by picking 1, 2, 3 or 4 sticks R4: The one who is forced to pick up the last matchstick loses the game. 38. How many ways I can pick up k different colors out of a palate of n different colors? (Hint: You may take k = 3 and n = 10) 39. Write two functions ReverseUsingPointers and ReverseString such that the former uses pointers to achieve the effect of reversing a given string and the later does not involve the pointers in making so. 40. Write a program to accepts students roll number and name; stores them in a structure; maintains a students record in a list ordered roll-number-wise. Show the effect of insertion and deletion on the students record. 41. Write a program compute difference between two dates.

42. Write a program to display sum of the first n terms of the series 1+1/32+1/52+ ... (Hint: n is an user input) 43. Write a program to compute the Armstrong numbers between 1 and 1000. Note that the Armstrong number follows the property as follows: The sum of the cubes of the digits in the number is the number itself. For example, 153=(1*1*1)+(5*5*5)+(3*3*3) implies that 153 is an Armstrong number. 44. Write a program to accept a number and check if it is Palindrom. How would you make it using pointers and without using the pointers? 45. Write functions ReadMatrix and MultiplyMatrix. Write a program to read two matrices and computer their multiplication and displays the output matrix in a two dimension table form. 46. Write a program to implement f(x) = f(x-1) + f(x-2) in C. Test your output for x = 5 47. Write an intelligent editor to simulate the following: While typing if a new word starts with the same letters as that of some previously typed word, the choice of selecting the word instead of typing the whole should be given. 48. Given center and the radius, a circle can be specified. Write a program that takes the specifications of two circles and answers the following 3 questions. Q1. Does C1 intersect C2? Q2. Does C1 touch C2, if so whether internally or externally? Q3. Does circle C1 completely embed circle C2?

49. Create an animation of stars falling from sky to ground and vanishing. Press any key to terminate 50. Write a program that does the following: The letters of English alphabet are randomly generated and accumulated in a bin. If at any instance it is possible to form a word out of the letters in the bin, the word is formed and displayed. The program ends here. You can always terminate the program by pressing any key in between. 51.Write a program to print all possible combinations of a user entered string. String should be at least 5 characters long. 52. Observe the phenomenon: 45*45=2025; 20+25=45.Write a program to generate the numbers between 32 and 99 that demonstrates this property. 53. You know 16 / 64 =1/4; Observe that you can obtain the result of the division by just cancelling one digit of denominator with the same that has occurred in the numerator. Generate all such pairs of numbers less than 100 that follow this characteristic. 54. There are some goats and ducks in a farm. There are 60 eyes and 86 foot in total. Write a program to find number of goats and ducks in the farm.

55. Bacteria are known to multiply very rapidly. If a certain container contains just one bacterium on the first day and there are twice as many on the next day. In this manner the number of bacteria in the container doubles itself everyday. Assuming that the container would be full on the 10th day with 13,312 bacteria, find the number of bacteria that was initially in the container on the first day. 56. Some cats got together and decided to kill 999919 rats. Each of the cats killed equal number of rats. Write a program to find number of cats. 57. Rita has a money pouch containing Rs.700. There are equal number of 25 paise coins, 50 paise and one rupee coins. Write a C program to find how many of each are there in Ritas pouch? 58. Write a C program to find a three digit number which is greater than the aggregate of its third, tenth and the twelfth parts by 58. 59. Write a C program to find a two digit number, the second digit of which is smaller than its first digit by 4, and if the number was divided by the digits sum, the quotient would be 7.

Вам также может понравиться