Anda di halaman 1dari 3

Questions

1. Write a function to reverse words in a given sentence. Eg: Today is first day of the month should be changed to month the of day first is Today 2. Write a function to find the first integer that repeats more than n times in a array of size m. Note array is not sorted. int findRepeatingInteger(int[] list, int size, int n) Eg: list 3,6,2,7,3,5,3,6,2,3 size = 9 n = 4 should return 3 3. Write a function to find a specified character in a array of charactes and replace with specified characters. void findAndReplace(char[] string, int str_len, char findchar, char[] replstring, int rep_str_len) Eg:string this is cat str_len = 11 findchar = i replstring = abc rep_str_len =3 should print this abcs abcs cat 4. An online auction site uses following table for charging service charges to sellers. Service Charge Table Rs 0 10000 10% Rs 10001 25000 8% Rs 25001 50000 6% Rs >=50001 5% Write the data structure to store the above table and also a function to compute service charge for a sale amount. double computeServiceCharge(double saleAmount) For Eg: saleAmount is 28000 the service charge will be calculated as follows Upto 10000 10% = 10000*10% = 1000 10001 25000 8% = 15000*8% = 1200 25001 28000 6% = 3000 * 6% = 180 Total Service Charge = 1000 + 1200 + 180 = 2380 5. Write a function to generate first n numbers for the following number sequence 4,6,9,12,15,18,21,26 . void generateFirstN(int n) Each number in this sequence is arrived at by taking the average of two consecutive odd prime numbers. Eg: Prime numbers 2,3,5,7,9,11,13,17 (3 + 5)/2 = 4 (5 + 7)/2 = 6 (7 + 11)/2 = 9 (11 + 13)/2 = 12 etc 6. Write a function to reverse every second word in a given sentence.

Eg: Today is first day of the month Today si first yad of ehe month

should

be

changed

to

7. Write

a function which removes all chars in str1 that occur in str2

Char[] removechars(char[] str1, char[] str2) Eg: str1 = today is Wednesday to is Wenes str2 = day should return

8. An online auction site uses following table for charging service charges to sellers. Service Charge Table Rs 0 20000 20% Rs 20001 50000 15% Rs 50001 100000 10% Rs >=100001 5% Write the data structure to store the above table and also a function to compute service charge for a sale amount. double computeServiceCharge(double saleAmount) For Eg: saleAmount is 55000 the service charge will be calculated as follows Upto 20000 20% = 20000*20% = 4000 20001 50000 15% = 30000*15% = 4500 50001 55000 10% = 5000 * 10% = 500 Total Service Charge = 4000 + 4500 + 500 = 9000 9. Write a function to generate first n numbers for the following number sequence 2,6,30,210,2310 . void generateFirstN(int n) Each number in this sequence is arrived at by multiplying the first n prime numbers. Eg: Prime numbers 2,3,5,7,9,11,13,17 2 = 2 2*3 = 6 2*3*5 = 30 2*3*5*7 = 210 2*3*5*7*11 = 2310 etc.. 10. Write a function to find number of occurance of specified substring in a given string. int findNumOccurances(char[] sentence, int len, char[] sub_str, int sub_str_len) Eg: this is a new issue len = 19 sub_str =is len = 2 Should return 3 as is occurs 3 times in the above string

Anda mungkin juga menyukai