Coding Test For CTS, TCS, Wipro Etc..
Coding Test For CTS, TCS, Wipro Etc..
Given an input Integer array, find the difference in the adjacent elements and print the largest difference
Input and Output Format :
First line of input consists of n, the number of elements. Next n lines correspond to the array elements. Output consist of largest
adjacent difference. Print "Invalid array size" when size of the array is a negative number and terminate the program
Print "Invalid input" when there is any negative number available in the input array and terminate the program.
Include a function named adjecentDifference(int numbers[], int size) whose return type is an Integer
Sample Input 1:
7
2
4
5
1
9
3
8
Sample Output 1:
8
Hint: The AdjecentElement Diff are :2,1,4,8,6,5 and Maximum diff is 8 which is obtained by 2-4 =2, 4-5=1,5- 1 =4, 1-9=8, 9-
3=6,3-8 =5
Sample Input 2:
5
1
7
3
-8
Sample Output 2:
Invalid input
2. Write a program to find the second smallest of all divisors of the given number.
For example, the divisors of 21 are 1,3,7 and 21. The second smallest divisor is 3.
Include a function named secondSmallest that accepts an integer argument and returns an integer. The function returns the
second smallest divisor or returns -1 if it is a negative number or if it is greater than 32767. If the function returns -1, print
Invalid Input.
Input and Output Format:
Input consists of a single integer. Output consists of a single integer. Refer sample output for formatting specifications.
Sample Input 1:
21
Sample Output 1:
3
Sample Input 2:
-241
Sample Output 2:
Invalid Input
Sample Input 3:
50000
Sample Output 3:
Invalid Input