简体   繁体   中英

Add, Subtract, Multiply 2 int Arrays

C# Assignment. Basically, I need to make a program to add, subtract , multiply 2 arrays. For example:

  • I accept strings of digits, such as "12345" "54321" .
  • I need to show its sum, difference, and product using arrays...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM