Question

C++ problem (in text form): Write a program that accepts two arrays of some dimension and...

C++ problem (in text form):

Write a program that accepts two arrays of some dimension and computes the limited sum of the arrays

0 0
Add a comment Improve this question Transcribed image text
Answer #1

problem : C++ problem

Write a program that accepts two arrays of some dimension and computes the limited sum of the arrays.

Solution :

#include <iostream>
using namespace std;
int main(){
   int n1,n2;
   cout << "Enter a first array size : ";     
   cin >> n1;                           //taking the input of size of the first array
   int i,a[n1];
   cout << "Enter the numbers to first array :" << endl;
   for(i=0;i<n1;i++){
           cout << "Enter a value of a[" << i << "] = ";
           cin >> a[i];           //taking the input values of the first array
   }
   cout << "Enter a second array size : ";
   cin >> n2;                                   //taking the input of size of the second array
   int b[n2];
   cout << "Enter the numbers to second array :" << endl;
   for(i=0;i<n2;i++){
           cout << "Enter a value of b[" << i << "] = ";
           cin >> b[i];           //taking the input values of the second array
   }
  
   cout << "Sum of the arrays : " << endl;
   /*if size of the first array greater than second array
   then we find the limited sum according to size of the second array
   otherwise size of the second array greater than first array
   then we find the limited sum according to size of the first array */
   if(n1 > n2){  
           for(i=0;i<n2;i++){
              cout << a[i] + b[i] << endl;
          }
   }else{
           for(i=0;i<n1;i++){
              cout << a[i] + b[i] << endl;
          }
   }  
}

output :

Add a comment
Know the answer?
Add Answer to:
C++ problem (in text form): Write a program that accepts two arrays of some dimension and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT