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
  • and then print their average. Write a C program that accepts a string of text from...

    and then print their average. Write a C program that accepts a string of text from the user and prints back the string without any of the vowels. For example, if the user entered "Hello, world", the program should print "Hll, wrld" Write a C program that accepts an integer in decimal from the user and prints the number of 1' bits in the integers binary representation. For example, if the user entered 14, the program should print 3 because...

  • PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments:...

    PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments: a list, and a number n. The program should generate 20 random numbers, in the range of 1 through 100, and assign each number to the list. The program should also ask the user to pick a number from 1 through a 100 and assign that number to n. The function should display all of the number in the list that are greater than...

  • Write a C program that accepts a phone number of the form +1(xxx)-xxx-xxxx where x is...

    Write a C program that accepts a phone number of the form +1(xxx)-xxx-xxxx where x is a digit, and displays the sum of all digits in the phone number.

  • c++ write a boolean function that accepts two integer arrays of size 10 as input parameters,...

    c++ write a boolean function that accepts two integer arrays of size 10 as input parameters, the function should return true if there are any similar values between the two arrays and shall return false if not, if there are similar values, print out on screen

  • Write a program with a function named isEqualArr that accepts a pair of arrays of integers...

    Write a program with a function named isEqualArr that accepts a pair of arrays of integers as parameters and returns true if the arrays contain the same elements in the same order. If the arrays are not the same length, your function should return false. For example, if the following arrays are declared: int[] arr1 = {10, 20, 30, 40, 50, 60}; int[] arr2 = {10, 20, 30, 40, 50, 60}; int[] arr3 = {20, 3, 50, 10, 68}; The...

  • Programming in C: Write a program that accepts an integer and two floating-point values and prints...

    Programming in C: Write a program that accepts an integer and two floating-point values and prints the sum of these values. Example: Input:12,13.14,6.7; Output:31.84. Use formatted I/O

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

  • Write a C program as follows: Single source code file Calls a function with an arbitrary...

    Write a C program as follows: Single source code file Calls a function with an arbitrary name (i.e. you name it) that accepts two arrays of the same size The function should add each element in the arrays together and place the values in a third array Each array element, each array address, and the sum are printed to the screen in tabulated format with headersI also would like to request that LOTS of comments be included, as I need...

  • Suppose we have two integer arrays with the same type, write an AL program to check...

    Suppose we have two integer arrays with the same type, write an AL program to check whether or not there are two integers, one from each array, with sum equal to zero. If there are such integers exist, print out all such combinations to the console window, otherise, print out "No integers in these two arrays, one from each array, with sum equal to zero." to the console window. December 3. 2018 For example, suppose we have the following two...

  • Write a program that reads a string from the keyboard and computes the two arrays of...

    Write a program that reads a string from the keyboard and computes the two arrays of integers upperCase, and lowerCase, each of size 26. The first one represents the frequency of upper case letters and the second one represents the frequency of lower case letters in the input string. After computing these arrays, the program prints the frequencies in the following format: The frequency of the letter A= The frequency of the letter B= Assume the input string contains only...

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
ADVERTISEMENT