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



techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#define MAX_SIZE 100 //Maximum size of the array

int main()
{
    int first[MAX_SIZE], second[MAX_SIZE];
    int i, num;

    //Enter size of array
    printf("Enter the size of the array : ");
    scanf("%d", &num);

    //Reading elements of array
    printf("Enter elements of first array : ");
    for(i=0; i<num; i++)
    {
        scanf("%d", &first[i]);
    }


   //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
    printf("\nElements of first array are: \n");
    for(i=0; i<num; i++)
    {
        printf("%d\t", first[i]);
    }


    //Printing all elements of second array
    printf("\nElements of second array are: \n ");
                                for(i=0; i<num; i++)
    {
        printf("%d\t", second[i]);
    }

  return 0;
}

Result

C language

     





Related Topics




Popular Posts