Declare three arrays:
A, B and C each size 3
Read these numbers into A using for loop and cin : 1, 2, 3
Read these numbers into B using for loop and cin: -1, -2, -3
C is A + B . this means you need to add each element of the array A to corresponding element of array B and then C is the sum.
Print the elements of array C (three elements)
#include <stdio.h>
int main()
{
double A[3];
double B[3];
int i;
for(i = 0; i < 3; i++)
{
printf("Enter number #%d: ",i+1);
scanf("%lf", &A[i]);
}
printf("\n\n");
for(i = 0; i < 3; i++)
{
printf("Enter number #%d: ",i+1);
scanf("%lf", &B[i]);
}
double C[3];
for(i = 0; i < 3; i++)
C[i] = A[i]+B[i];
printf("\n\nOutput\n");
for(i = 0; i < 3; i++)
printf("%g ",C[i]);
return 0;
}
Comments