Tech Study

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.

using System;
class Program
{
    static void Main()
    {
        int[] arr = new int[100];
 
        int[] first = new int[100];
        int[] second = new int[100];
 
        int i, num;
 
        //Reads size of the array
        Console.WriteLine("Enter size of the array: ");
        num = Convert.ToInt32(Console.ReadLine());
        //Reads elements in array
        Console.WriteLine("Enter elements in the array: ");
        for (i = 0; i < num; i++)
        {
            first[i] = Convert.ToInt32(Console.ReadLine());            
        }
 
        //Copy all elements from first array to second array
        for (i = 0; i < num; i++)
        {
            second[i] = first[i];
        }
 
        //Printing all elements of first array entered by user
        Console.WriteLine("Elements of first array are:");
        for (i = 0; i < num; i++)
        {
            Console.Write(first[i]+"\t");            
        }
 
        //Printing all elements of second array
        Console.WriteLine("\nElements of second array are:");        
        for (i = 0; i < num; i++)
        {
           Console.Write(second[i]+ "\t");
        }
 
 
        Console.ReadLine();
    }
 
}

Result

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

TaggedWrite C program to copy all elements of one array to another

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more