#include<iostream>
using namespace std;
int main(){
int n, ele;
cout<<"Enter the size of the array.\n";
cin>>n;
int A[n];
cout<<"Enter elements in the array\n";
for(int i =0;i<n;i++){
cin>>A[i];
}
cout<<"Enter the element to be divisible by.\n";
cin>>ele;
int sum = 0;
for(int i =0;i<n;i++){
if(A[i]%ele==0){
sum += A[i];
}
}
cout<<"The sum is "<<sum<<endl;
return 0;
}
Output
Enter the size of the array.
6
Enter elements in the array
2 3 4 5 6 7
Enter the element to be divisible by.
3
The sum is 9
Program:
Output