#include <iostream>
using namespace std;
int getSum(int arr[],int n){
int sum=0;
for(int i=0;i<n;i++){
sum=sum+arr[i];
}
return sum;
}
float getSum(float arr[],int n){
float sum=0;
for(int i=0;i<n;i++){
sum=sum+arr[i];
}
return sum;
}
int main()
{
int n1,n2;
cout<<"Enter number of elements in integer array: ";
cin>>n1;
cout<<"Enter number of elements in float array: ";
cin>>n2;
int arr1[n1];
float arr2[n2];
cout<<"\nEnter "<<n1<<" integer elements:\n";
for(int i=0;i<n1;i++){
cin>>arr1[i];
}
cout<<"\nEnter "<<n2<<" float elements:\n";
for(int i=0;i<n2;i++){
cin>>arr2[i];
}
cout<<"\nThe sum of the integer elements is: "<<getSum(arr1,n1);
cout<<"\nThe sum of the float elements is: "<<getSum(arr2,n2);
return 0;
}
Comments
Leave a comment