Subtract two Array Data structure by R4R Team

Array:

Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

Subtraction of second Array by first Array:
Example-
Array1 is {1,2,3,4,5}
Array2 is {1,0,1,1,0}
//Subtraction is {0,2,2,3,5}

program-

#include < stdio.h>
int main()
{
int a[5],b[5],c[5],i;
printf("Enter 5 number in first array\n");
for(i=0;i< 5;i++)
scanf("%d",&a[i]);
printf("Enter 5 number in second array\n");
for(i=0;i< 5;i++)
scanf("%d",&b[i]);
// Now Subtract first array by second array
for(i=0;i< 5;i++)
{
c[i]=a[i]-b[i];
}
//Now traverse
printf("After Subtraction\n");
for(i=0;i< 5;i++)
printf("%d,",c[i]);
}


output-

Enter 5 number in first array
6 7 8 9 10
Enter 5 number in second array
1 2 3 4 5
After subtraction
5,5,5,5,5,

-In this program, we take a input of two Array.
-then we traverse both array and print the subtraction for each value.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!