Advertisement
eitherlast

c# first try

Oct 18th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7.  
  8. namespace _1._1
  9. {
  10. class Program
  11. {
  12. static void CreateArray(int n, ref int[] arr)
  13. {
  14. Random r = new Random();
  15. Thread.Sleep(1);
  16.  
  17. for (int i = 0; i < n; i++)
  18. {
  19. Array.Resize(ref arr, i + 1);
  20. arr[i] = r.Next(1000);
  21. }
  22.  
  23. foreach (int item in arr)
  24. Console.Write(item + " ");
  25. }
  26.  
  27. /* static int[] test()
  28. {
  29. int[] nums = new int[40];
  30. for (int i = 0; i < 40; i++)
  31. nums[i] = i + 1;
  32. return nums;
  33. } */
  34.  
  35.  
  36. static double[] CreateArray1(ref double[] newarr)
  37. {
  38. int n = 10;
  39. Array.Resize(ref newarr, n);
  40. newarr[0] = 1;
  41.  
  42. for (int i = 1; i < n; i++)
  43. {
  44. newarr[i] = newarr[i - 1] * (-1.0/(2 * i + 1));
  45. }
  46.  
  47. foreach (double item in newarr)
  48. Console.WriteLine("{0:f5} ", item);
  49. return newarr;
  50. }
  51.  
  52.  
  53. static void Main()
  54. {
  55. // int n = 10;
  56. // int[] arr = new int[0];
  57.  
  58. // CreateArray1(n, ref arr);
  59. double[] newarr = new double[0];
  60.  
  61. CreateArray1(ref newarr);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement