It may not work for all , the parameter input is double what happens
if the user gives a number greater the range of int datatype , in the
return statement during type casting overflow in int occurs and wrong
value is returned .
check this
http://www.ideone.com/oZbCf
i have given the input as 2147483649 which is one greater the range of
int .. check the output ...

On Aug 3, 6:26 pm, Ashish Sachdeva <[email protected]> wrote:
> @poised:
> i think this:
>
> double round(double num)
> { return (int)(num+0.5)
>
> }
>
> works for all...http://www.ideone.com/WfEIw
>
> On Aug 3, 5:45 pm, Gene <[email protected]> wrote:
>
>
>
>
>
>
>
> > Your solution to 1 works fine. I hope you get the job. But it needs
> > O(N) additional storage for the stack. You can also do with constant
> > additional storage.
>
> > #include <stdio.h>
> > int main(void)
> > {
> > #define N (sizeof a / sizeof a[0])
> >   int a[] = {7, 9, 4, 8, 2};
> >   int result[N], i, product;
> >   for (i = 0, product = 1; i < N; product *= a[i++])
> >     result[i] = product;
> >   for (i = N - 1, product = 1; i >= 0; product *= a[i--])
> >     result[i] *= product;
> >   for (i = 0; i < N; i++)  printf("%d ", result[i]);
> >   printf("\n");
> >   return 0;
>
> > }
>
> > On Aug 3, 7:08 am, Poised~ <[email protected]> wrote:
>
> > > I am not looking for answer. Just sharing these Section 2 questions:
>
> > > 1. Given an array arr[] of n integers, construct a Product Array prod[] 
> > > (of
> > > same size) such that prod[i] is equal to the product of all the elements 
> > > of
> > > arr[] except arr[i]. Solve it without division operator. Give an efficient
> > > code.
> > > (if you are interested, here is my solution:http://ideone.com/EaTUF,
> > > developed at the test time itself).

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to