Suppose x1 and x2 are two type double variables that you want to add as
integers and assign to an integer variable. Construct a C++ statement
for doing so.What if you want to add them as type double and then
convert to int?
Ans:
Either of the following would work for the first task:
int pos = (int) x1 + (int) x2;
int pos = int(x1) + int(x2);
To a d d t h e m a s t y p e double and then convert, you could do either of the following:
int pos = (int) (x1 + x2);
int pos = int(x1 + x2);
Ans:
Either of the following would work for the first task:
int pos = (int) x1 + (int) x2;
int pos = int(x1) + int(x2);
To a d d t h e m a s t y p e double and then convert, you could do either of the following:
int pos = (int) (x1 + x2);
int pos = int(x1 + x2);
0 Questions:
Post a Comment