Write C# program to copy all elements of one array to another


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. using System;
  2. class Program
  3. {
  4. static void Main()
  5. {
  6. int[] arr = new int[100];
  7.  
  8. int[] first = new int[100];
  9. int[] second = new int[100];
  10.  
  11. int i, num;
  12.  
  13. //Reads size of the array
  14. Console.WriteLine("Enter size of the array: ");
  15. num = Convert.ToInt32(Console.ReadLine());
  16. //Reads elements in array
  17. Console.WriteLine("Enter elements in the array: ");
  18. for (i = 0; i < num; i++)
  19. {
  20. first[i] = Convert.ToInt32(Console.ReadLine());
  21. }
  22.  
  23. //Copy all elements from first array to second array
  24. for (i = 0; i < num; i++)
  25. {
  26. second[i] = first[i];
  27. }
  28.  
  29. //Printing all elements of first array entered by user
  30. Console.WriteLine("Elements of first array are:");
  31. for (i = 0; i < num; i++)
  32. {
  33. Console.Write(first[i]+"\t");
  34. }
  35.  
  36. //Printing all elements of second array
  37. Console.WriteLine("\nElements of second array are:");
  38. for (i = 0; i < num; i++)
  39. {
  40. Console.Write(second[i]+ "\t");
  41. }
  42.  
  43.  
  44. Console.ReadLine();
  45. }
  46.  
  47. }

Result

C# language techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.