Question

1. Enter two integer arrays: array1-129, 0, -56, 4, -7 and array2-19, 12, -36, -2, 12 3. Write the code to form and display a

2. Enter a positive 5-digit integer via the keyboard. Display each digit and fol- lowed by the sum of those digits. Prompt th
i need help writing these programs in c++ format
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.

Code:

#include<iostream>
using namespace std;
int size;
void get_array(int *array)
{
   cout<<"Enter elements: ";
   for(int i=0;i<size;i++) cin>>*(array+i);
}
void process_arrays(int *array1, int *array2, int *array3)
{
   for(int i=0;i<size;i++)
   {
       *(array3+i) = *(array1+i) + *(array2+i);
   }
}
void show_array(int *array)
{
   for(int i=0;i<size;i++) cout<<*(array+i)<<" ";
}
int main()
{
   cout<<"Enter size: ";cin>>size;
   int *array1, *array2, *array3;
   array1 = new int[size];//allocate memory
   array2 = new int[size];
   array3 = new int[size];
   get_array(array1);//read arrays
   get_array(array2);
   process_arrays(array1, array2, array3);//generate array3
   show_array(array3);
}

Output:

Enter size: 5 Enter elements: 29 e-56 47 Enter elements: 9 12-36 -2 12 38 12-92 2 5 cess exited after 17.11 seconds with retu

2.

(k/10n)%10 gives nth digit in a number

Code:

#include<iostream>

using namespace std;

int main()
{
   int num;
   while(1)
   {
       cin>>num;
       if(num<0) break;
       cout<<"digits are: ";
       int k=num;
       cout<<(k/10000)%10<<" "<<(k/1000)%10<<" "<<(k/100)%10<<" "<<(k/10)%10<<" "<<k%10<<endl;
       int sum=0;
       sum=sum + (k/10000)%10 + (k/1000)%10 + (k/100)%10 + (k/10)%10 + k%10;
       cout<<"sum of digits: "<<sum<<endl;
   }
}

Output:

23546 igits are: 2 35 46 sum of digits: 20 98482 digits are: 98482 sum of digits: 31 98231 digits are: 90231 sum of digits: 1

Add a comment
Know the answer?
Add Answer to:
i need help writing these programs in c++ format 1. Enter two integer arrays: array1-129, 0,...
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
  • PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from...

    PLEASE HELP!!!I need help with the following JAVA PROGRAMS. Please ready carefully. So this comes from tony gaddis starting out with java book. I have included the screenshot of the problems for reference. I need HELP implementing these two problems TOGETHER. There should be TWO class files. One which has TWO methods (one to implement problem 8, and one to implement problem 9). The second class should consist of the MAIN program with the MAIN method which calls those methods....

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview...

    Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters...

    Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...

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