Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Text;
  6.  
  7. namespace NumSequenceCalculator
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("This app calculates a sequence of numbers from 1 to n. n must NOT be bigger" +
  14. " than 9. The app works until the command END.");
  15.  
  16. Console.Write("Enter a formula with argument n. For example: a=n+1 ");
  17. var inputFormula = Console.ReadLine().Split('=');
  18. Console.Write("Calculate for n= ");
  19. int k = int.Parse(Console.ReadLine());
  20. char counter = '1';
  21.  
  22. while (inputFormula[1] != "END")
  23. {
  24.  
  25.  
  26. while (int.Parse(counter.ToString()) != k+1)
  27. {
  28. List<char> charList = inputFormula[1].ToList();
  29. for (int i = 0; i < charList.Count; i++)
  30. {
  31. if (charList[i] == 'n')
  32. {
  33. charList[i] = counter;
  34. }
  35. //!
  36. }
  37. counter++;
  38.  
  39. var foo = new string(charList.ToArray());
  40. var sb = new StringBuilder();
  41. var dt = new DataTable();
  42. sb.Append(foo).Append(" = ").Append(dt.Compute(foo, ""));
  43.  
  44.  
  45. Console.WriteLine(sb.ToString());
  46. }
  47.  
  48. inputFormula = Console.ReadLine().Split('=');
  49. k = int.Parse(Console.ReadLine());
  50. }
  51.  
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement