Source code:
/* To add and subtract of two one dimensional array elements and store it in a third and fourth one dimensional array and print it */
#include <stdio.h>
int main()
{
int arr1[5];
int arr2[5];
int arr3[5];
int arr4[5];
int i=0;
/*Read array elements*/
printf("For 1st array:-\n");
for (i=0; i<5; i++)
{
printf("Enter the value for %d: ",i);
scanf("%d",&arr1[i]);
}
printf("For 2nd array:-\n");
for (i=0; i<5; i++)
{
printf("Enter the value for %d: ",i);
scanf("%d",&arr2[i]);
}
for(i=0;i<5;i++)
{
arr3[i]=arr1[i]+arr2[i];
arr4[i]=arr1[i]-arr2[i];
}
printf("Sum of two array:-\n");
for (i=0; i<5; i++)
{
printf("%d\n",arr3[i]);
}
printf("Subtraction of two array:-\n");
for (i=0; i<5; i++)
{
printf("%d\n",arr4[i]);
}
return 0;
}
No comments:
Post a Comment