You are provided with 3 numbers: input1, input2 and input3.
Each of these are four digit numbers within the range >= 1000 and <= 9999, i.e.
1000 <= input1 <= 9999
1000 <= input2 <= 9999
1000 <= input3 <= 9999
You are expected to find the key using the below formula:
Key = [LARGEST digit in the thousands place of all three numbers – smallest digit in the thousands place of all three numbers] [LARGEST digit in the hundreds place of all three numbers – smallest digit in the hundreds place of all three numbers] [Largest digit in the tens place of all three numbers – smallest digit in the tens place of all three numbers] [LARGEST digit in the units place of all three numbers – smallest digit in the units place of all three numbers]
Cognizant Solutions | CodeGladiators Solutions
For Example
If input1 = 3521,input2 = 2452, input3 = 1352,
Then key = [3-1][5-3][5-2][2-1] = 2231
Assuming that the 3 numbers are passed to the given function, Complete the find and return the Key.
Solution
import java.io.*;
import java.util.*;
import java.util.Collections;
class UserMainCode
{
static int maxOfThree(int x, int y, int z) {
return z > (x > y ? x : y) ? z : ((x > y) ? x : y);
}
static int minOfThree(int a, int b, int c) {
return (a<b)?(a<c?a:c):(b<c?b:c);
}
public static void main(String[] args)
{
int input1 = 3521;
int input2 = 2452;
int input3 = 1352;
int u=0,t=0,h=0,th=0;
int length = 4;
while(length!=0){
if(length == 4) {
u = maxOfThree(input1%10,input2%10,input3%10) - minOfThree(input1%10,input2%10,input3%10);
}
if(length == 3){
t = maxOfThree(input1%10,input2%10,input3%10) - minOfThree(input1%10,input2%10,input3%10);
}
if(length == 2){
h = maxOfThree(input1%10,input2%10,input3%10) - minOfThree(input1%10,input2%10,input3%10);
}
if(length == 1){
th = maxOfThree(input1%10,input2%10,input3%10) - minOfThree(input1%10,input2%10,input3%10);
}
input1/=10;
input2/=10;
input3/=10;
length--;
}
System.out.println(th*1000+h*100+t*10+u);
}
}
Coding Questions
- Coding Question :
Write a complete C program to convert a given temperature in Centigrade scale to its equivalent Fahrenheit scale.
- Coding Question :
Write a function to swap the value of 2 variables without using any additional variable. The change should be permanent.
- Coding Question :
Write a program to check a number whether it is odd or even by the bitwise operator.
- Coding Question :
Write a C program to print the following pattern(till n rows, where n is taken as input).
1
0 1
0 1 0
1 0 1 0
1 0 1 0 1 - Coding Question :
Write a C program to accept three integer numbers as the length of three sides of a triangle, test the validity of lengths, and classify the triangle.
- Coding Question :
Write a program to generates all combinations of 1,2 and 3 using for loop.
- Coding Question :
Write a program in C to find the roots of a quadratic equation. Your program should print the imaginary roots in the form a+ib.
- Coding Question :
Write a program to print a Pattern.
- Coding Question :
Write a program to find the sum of the digits of a number.
- Coding Question :
Write a program to check a number is palindrome or not.
- Coding Question :
Write a C program to print the Pattern.
1
1 0 1
1 0 1 0 1
1 0 1 0 1 0 1 - Coding Question :
Write a program to accept a number and find the sum of its individual digits repeatedly till the result is a single digit.
- Coding Question :
Write a program to compute
e= 1+ 1/1! + 1/2! + 1/3! ….1/n! with accuracy of 0.001%.
- Coding Question :
Write a program to print the sum of three digits prime numbers.
- Coding Question :
Write a C program to check a number is prime or not.
- Coding Question :
Write a program to print the following pattern (Number of lines should be given as input by the users).
- Coding Question :
Write a C program to check a number is prime or not.
- Coding Question :
Write a program which take an integer as input and print the digits of an integer in words, after storing in a character array. [ if input : 2403 , output : Two Four Zero Three]
- Coding Question :
Write a C program to count the frequency of each vowel from a user-supplied string.
- Coding Question :
The equation x2+y2=r2 represent a circle which centers at origin and radius is r. Write a program that read r from the keyboard and print the number of points with integer co-ordinate that lie on the circumference of the circle.
- Coding Question :
Write a program to print Pascal’s triangle.
- Coding Question :
Write a program to display the prime factors of an integer.(The number is input).
- Coding Question :
Write a program which will print the following pattern(no of the line is input).
- Coding Question :
Write a C program to print the prime numbers between 1 to 100.
- Coding Question :
Write a C program that will search the kth element in a list of n integers.
- Coding Question :
Write C program to solve: xsin(x)
- Coding Question :
Write C programs to solve : x3=249
Write a program to find the value of sin(x) , x=0,15,30,…,345,360 with an accuracy of 10-4 avoiding use of abs function.
- Coding Question :
Write a program to convert decimal numbers in the range 1 to 9999 in to Roman numerals where , I=1,V=5, X=10, L=50,C=100,D=500,M=1000 and assuming L=5000.
- Coding Question :
Write a C program to find Greatest Common Divisor(GCD) for n number.
- Coding Question :
Write a recursive function to print the content of an array on reverse order, Write the main() function to call that recursive function.
- Coding Question :
Write a program to print Fibonacci series using recursive.
- Coding Question :
Write a c-program to convert binary number to equivalent decimal number.
- Coding Question :
Write a program to check a number is special or not. (Special is a number which is equal to the sum of factorial of each digit of the given number).
- Coding Question :
Write a C-program to implement the Tower of Hanoi problem using recursion.
- Coding Question :
Write two C programs that calculates factorial of a number using recursion and iteration.
- Coding Question :
Write a function to sort the characters of the string passed to it as argument.
- Coding Question :
Write a program in C which prints the smallest divisor of an integer , for example smallest divisor of 77 is 7.
- Coding Question :
Write a C program to find the average of n numbers.
- Coding Question :
Write a program to create an array of n elements and then print maximum and minimum elements from that array.
- Coding Question :
Write a C program which will take input in a 2D array and then take one integer as input and search it is available or not, if it is available display the row and column of the integer.
- Coding Question :
Write a program to find the transpose of a matrix.
- Coding Question :
Write a program to insert an element (given by the user) into an array in a particular position(given by the user).
- Coding Question :
Write a recursive C program to multiply two 3×3 matrices.
- Coding Question :
Write a C-program to implement binary searching.