Number problems

1 view
Skip to first unread message

sourabh0612

unread,
May 8, 2010, 11:45:44 AM5/8/10
to DS & Algo@itbhu
I have 2 int variables whose product is not in the range of int.
So,I multiplied both and assigned it to a long long variable.But when
i print the long long variable it shows a garbage value.
Ex-
int abc=99999998;
int def=1500;
long long int po=abc*def;
cout<<po<<endl;

Output-

-323858360

Someone please reply asap, need it to debug my code for codejam.

--
You received this message because you are subscribed to the Google Groups "DS & Algo@itbhu" group.
To post to this group, send an email to ds--al...@googlegroups.com.
To unsubscribe from this group, send email to ds--algoitbh...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ds--algoitbhu?hl=en-GB.

Vipul Agrawal

unread,
May 8, 2010, 12:22:17 PM5/8/10
to ds--al...@googlegroups.com
cast it before assign multiplication result to variable po

int abc=99999998;
int def=1500;
long long int po=(long long)abc*def;
cout<<po<<endl;


....
regards,
vipul

sourabh0612

unread,
May 8, 2010, 12:25:16 PM5/8/10
to DS & Algo@itbhu
thnx..

On May 8, 8:45 pm, sourabh0612 <sourabh3...@gmail.com> wrote:
> I have 2 int variables whose product is not in the range of int.
> So,I multiplied both and assigned it to a long long variable.But when
> i print the long long variable it shows a garbage value.
> Ex-
> int abc=99999998;
> int def=1500;
> long long int po=abc*def;
> cout<<po<<endl;
>
> Output-
>
> -323858360
>
> Someone please reply asap, need it to debug my code for codejam.
>
> --
> You received this message because you are subscribed to the Google Groups "DS & Algo@itbhu" group.To post to this group, send an email tods--a...@googlegroups.com.To unsubscribe from this group, send email tods--algoitb...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages