need help in implementing the code for the following program

+2 bhanu prasad · January 25, 2015
declare an integer array and pass some values,then  find out the difference between all the values(assume all are different values).then you have to display the smallest difference among all those differences found out as the output. 
thanks in advance :)

Post a Reply


Oldest  Newest  Rating
+1 bhanu prasad · January 27, 2015
thank you lazar bulic,i got the output
0 Lazar Bulic · January 25, 2015
So I guess there are many ways to solve this but one is on my mind. I will try to help you but you write the code. If you have problem with that I will also help you with the code.

Ask for the user to input the number of values in an array. Use that number to declare an array.
The different between all values only depends on the starting value. If I understand the task correctly. So if you have array 
A = {3,5,2} u have 3 different results. 1) 3-5-2 = -4    2) 5-3-2 = 0    3) 2-5-3 = -6
So the smallest value is the one starting with the smallest value in the array.
But that doesn't concern you as you can make a variable max that will hold the smallest value of difference and compare it each time the new one is calculated.  

This biggest hint I will give you is: You will need 2 for loops. One inside the other! 
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator