Question

a. write a program that calculates the sum of two numbers x and y and then...

a. write a program that calculates the sum of two numbers x and y and then the program should call the function by address and prints the sum

b. write a program that stores 10 integers provided at run time in an array. the program should prompt the user for a random integer exit in the array, the value must be replaced by a-1

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

Here is the completed code for this problem. Since you didn’t mention the language, my best guess was C++. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

//first program

#include<iostream>

using namespace std;

//method to find and print the sum of two numbers passed by the addresses

void sum(int *a, int *b){

              cout<<*a<<" + "<<*b<<" = "<<(*a+*b)<<endl;

}

int main(){

              int x,y;

              //reading x and y

              cout<<"Enter the value for x: ";

              cin>>x;

              cout<<"Enter the value for y: ";

              cin>>y;

              //finding and printing sum, by passing the addresses of x and y to sum method

              sum(&x,&y);

              return 0;

}

//second program

#include<iostream>

using namespace std;

int main(){

              //declaring an integer array of 10 numbers

              int array[10];

              //number to replace

              int a;

              //prompting and reading 10 numbers

              cout<<"Enter 10 numbers: ";

              for(int i=0;i<10;i++){

                           cin>>array[i];

              }

              //prompting and reading number to replace

              cout<<"Enter a number to replace: ";

              cin>>a;

              //looping through array, finding a

              for(int i=0;i<10;i++){

                           if(array[i]==a){

                                         //found, replacing with a-1

                                         array[i]=a-1;

                           }

              }

              //displaying the modified array

              cout<<"Updated array: ";

              for(int i=0;i<10;i++){

                           cout<<array[i]<<" ";

              }

              cout<<endl;

              return 0;

}

/*OUTPUT1*/

Enter the value for x: 12

Enter the value for y: 15

12 + 15 = 27

/*OUTPUT2*/

Enter 10 numbers: 1 3 5 7 8 9 12 44 53 0

Enter a number to replace: 12

Updated array: 1 3 5 7 8 9 11 44 53 0

Add a comment
Know the answer?
Add Answer to:
a. write a program that calculates the sum of two numbers x and y and then...
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
  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • Need to write a MIPS assembly program that finds the minimum and maximum and sum of...

    Need to write a MIPS assembly program that finds the minimum and maximum and sum of a stored array. It also finds the locations of the minimum and maximum. The interaction between the main program and the function is solely through the stack. The function stores $ra immediately after being called and restores $ra before returning to main. The main program reserves a static C like array (index starts from 0) of 10 elements and initializes it. The maximum should...

  • Write a complete program that: 1. Promts the user to enter 10 numbers. 2. saves those...

    Write a complete program that: 1. Promts the user to enter 10 numbers. 2. saves those numbers in a 32 bit integer array. 3. Calculates the sum of the numbers and displays it. 4. Calcualtes the mean of the array and displays it. 5. Prints the array with the same order it was enterd. 6. Rotates the members in the array forward one position for 9 times. so the last rotation will display the array in reversed order. Print the...

  • Write a program in C that creates an array of 100 random numbers from 0-99. The...

    Write a program in C that creates an array of 100 random numbers from 0-99. The program sums the random numbers and prints the sum.  It then writes the numbers to a new file using open, close and write. Then looks in the current directory for files that match the pattern “numbers.XXXX”. For each file, open the file and read the file. You can assume that the file will contain 100 integers. Sum the integers. Print the filename and the sum...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount...

    Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end...

  • Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into...

    Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array

  • write a c++ program that prompts a user for a number then attempts to allocate an...

    write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...

  • Write a C++ program that uses a 4 X 4 array and randomly place each integer...

    Write a C++ program that uses a 4 X 4 array and randomly place each integer from 1 to 16 into the 16 squares. The program calculates the magic number by adding all the numbers in the array and then dividing the sum by 4. The 4 X 4 array is a magic square if the sum of each row, each column and each diagonal is equal to the magic number. Your program must contain at least the following functions...

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