Solved programming problem

Add two 1D array in C.

Source code

#include<stdio.h>

int main()

{

    int array[100],array1[100],sum[100];

    int i,n,m,index;

    printf("Please Enter The 1st array size: ");

    scanf("%d",&n);

    printf("
Please Enter %d elements of the array: 
",n);

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

    {

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

    }

    printf("
Please Enter The 2nd array size: ");

    scanf("%d",&m);

    printf("
Please Enter %d elements of the array: 
",m);

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

    {

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

    }

    ///add

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

    {

        sum[i]=array[i]+array1[i];

    }

    if(n!=m) /// total element of two array need to be same.

    {

        printf("Not possible to Add
");

    }

    else

    {

        printf("
The sum of two array is: ");

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

        {

            printf("%d ",sum[i]);

        }

    }

    printf("
");

    return 0;

}

Output

Please Enter The 1st array size:3

Please Enter 3 elements of the array: 1 2 3

Please Enter The 2nd array size:3

Please Enter %d elements of the array: 3 2 1

The sum of two array is 4 4 4

Join the discussion

Add your comment

2 previous comments

finasteride interactions

<a href=https://propecia2buy.top/>propecias</a> Hi guys, first post on evolution so I figured I d reach out and get some guidance from those who know better then myself, as I am completely new to this

PiesZoogs

NB causes 15 of childhood cancer related mortality and overall survival rate for metastatic tumors is considerably low, 40 after 5 years 2, 3 <a href=http://buylasixon.com/>lasix po to iv conversion</a> I loved that look