C program - find mistake

In following program, because of a typo mistake, the test() function returns zero. Actual expected value is different than zero. Assuming the typo mistake is fixed find the expected output and enter the number as answer.
var nums = [100,1000,10,1010];
Code
  1. function  test() {

  2.   var a = nums[0];

  3.   var b = nums[0];

  4.  

  5.   for (i = 0; i < a.length; i++) {

  6.     if (nums[i] > a) a = nums[i];  

  7.     if (nums[i] <= b) b = nums[i];

  8.   }

  9.   return b - a;

  10. }
Copyright GeekInterview.com

Showing Answers 1 - 6 of 6 Answers

Aditya Natuva

  • Feb 28th, 2015
 

array elements should be give in paranthesis({}) but not in squre brackets(()).

  Was this answer useful?  Yes

snehal

  • Mar 12th, 2015
 

-1000

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions