Array implementation to add the first n natural numbers
#include <iostream.h>
int main()
int n;
int sum=0;
cout<<"Please enter the size of the array"<<endl;
cin>>n;
int add[10];
cout<<"please enter the elements of the array"<<endl;
for(int i=0;i<n; i++)
cin>>add[i];
for(int i=0;i<n; i++)
sum=sum+add[i];
cout<<"the sum of the first n natural numbers ="<<sum<<endl;
return 0;
}
Array implementation to add the first n natural numbers
#include <iostream.h>
int main()
int n;
int product=1;
cout<<"Please enter the size of the array"<<endl;
cin>>n;
int Pro[10];
cout<<"please enter the elements of the array"<<endl;
for(int i=0;i<n; i++)
cin>>Pro[i];
for(int i=0;i<n; i++)
product=product*Pro[i];
cout<<"the product of the first n natural numbers ="<<product<<endl;
return 0;
}
Array implementation for product of two arrays using c++ programming
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Please enter the size of the array: ";
cin >> n;
// Declare arrays with the given size (assuming n <= 10 for simplicity)
int a1[10], a2[10], a3[10];
// Input elements for the first array
cout << "Please enter the elements of the first array: ";
for (int i = 0; i < n; i++) {
cin >> a1[i];
}
// Input elements for the second array
cout << "Please enter the elements of the second array: ";
for (int i = 0; i < n; i++) {
cin >> a2[i];
// Compute the product of corresponding elements from a1 and a2
for (int i = 0; i < n; i++) {
a3[i] = a1[i] * a2[i];
// Output the resulting products
cout << "The product of the corresponding elements of the arrays is: ";
for (int i = 0; i < n; i++) {
cout << a3[i] << " ";
cout << endl;
return 0;