C# Assignment. Basically, I need to make a program to add, subtract , multiply 2 arrays. For example:
"12345"
"54321"
. Example:
Input: "12345" "54321"
Output:
SUM= 66666
DIFFERENCE= 41976
PRODUCT= 670592745
You didn't say how you get the string-numbers (ie "12234") in the input(read from file maybe? or stdin?), but inorder to convert them to integers, use the following:
int x = Int32.Parse("12345");
or this:
int x;
Int32.TryParse("12345", out x);
the last one gives you error-free solution, since some strings cannot be converted to int (like ",/.,.,/"), so TryParse
returns false in this case.
that makes an integer out of a string.
Now, for adding, subtracting and such, you can apply the regular operators of +
, -
,..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.