Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Saturday, September 10, 2022

C program to copy one array elements to another array using 2D array

C program to copy one array elements to another array using 2D Array in QBASIC


#include <stdio.h>

#include<conio.h>

main()

{

    int arr1[100], arr2[100];

    int i, n;

       printf("\n\nCopy the elements one array into another array :\n");

       printf("----------------------------------------------------\n");

  printf("Input the number of elements to be stored in the array :");

       scanf("%d",&n);

       printf("Input %d elements in the array :\n",n);

       for(i=0;i<n;i++)

        {

      printf("element - %d : ",i);

      scanf("%d",&arr1[i]);

    }

    /* Copy elements of first array into second array.*/ 

    for(i=0; i<n; i++)

    {

        arr2[i] = arr1[i];

    }


    /* Prints the elements of first array   */

    printf("\nThe elements stored in the first array are :\n");

    for(i=0; i<n; i++)

    {

        printf("% 5d", arr1[i]);

    }


    /* Prints the elements copied into the second array. */

    printf("\n\nThe elements copied into the second array are :\n");

    for(i=0; i<n; i++)

    {

        printf("% 5d", arr2[i]);

    }

       printf("\n\n");

       getch();

}


Output:




No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages