Read two arrays add and store the result in the third array and find the average of the element

Write a program to read two arrays add and store the result in the third array and find the average of the element

#include<stdio.h>

int main() {
	float a[15],b[15],c[15],sum=0,avg;
	int n,i;
	printf("How many elements do you want to enter?\n");
	scanf("%d",&n);
	printf("Enter element of the first array:\n");
	for(i=0;i<n;i++)
	scanf("%f",&a[i]);

	printf("Enter elements of the second array:\n");
	for(i=0;i<n;i++)
	scanf("%f",&b[i]);

	for(i=0;i<n;i++) {
		c[i]=a[i]+b[i];
		sum+=c[i];
	}
	avg=sum/n;

	printf("The average is %.3f",avg);

	return 0;
}

Output

How many elements do you want to enter?
4
Enter element of the first array:
1
2
3
4
Enter elements of the second array:
4
5
6
7
The average is 8.000

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments