ellapt

T11.6.IntsInStringSum

Jan 25th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. using System;
  2.  
  3. class IntsInStringSum
  4. {
  5. static void Main()
  6. {
  7. Console.WriteLine("Read positive integer values written into string, separated by spaces,\nand calculate their sum");
  8.  
  9. string intVal = " 43 68 9 23 318 10 ";
  10. int sum = 0;
  11. intVal = intVal.Trim();
  12. string[] posInts = intVal.Split(' ');
  13. for (int i = 0; i < posInts.Length; i++)
  14. {
  15. sum = sum + int.Parse(posInts[i]);
  16. }
  17. Console.WriteLine(sum);
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment