0% found this document useful (0 votes)
76 views1 page

Coding Test For CTS, TCS, Wipro Etc..

The document contains instructions for two programming problems: 1. Write a function to find the largest difference between adjacent elements in an integer array. It should return "Invalid array size" for a negative size and "Invalid input" if a negative number is in the array. 2. Write a function to find the second smallest divisor of a given number. It should return -1 for a negative input or a number over 32767, printing "Invalid Input" in those cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views1 page

Coding Test For CTS, TCS, Wipro Etc..

The document contains instructions for two programming problems: 1. Write a function to find the largest difference between adjacent elements in an integer array. It should return "Invalid array size" for a negative size and "Invalid input" if a negative number is in the array. 2. Write a function to find the second smallest divisor of a given number. It should return -1 for a negative input or a number over 32767, printing "Invalid Input" in those cases.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. Read the question carefully and follow the input and output format.

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

You might also like