Question

Write a C++ program which inputs an array of integers from user then pass array pointer...

Write a C++ program which inputs an array of integers from user then pass array pointer to function which will return sum of whole array. Also do same action by using address-based argument of array to another function.

Note: In this you need to declare two factions: 1. With argument of pointer type. 2.With argument type of address type

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

Program:

#include <iostream>
using namespace std;
int pointertype(int *,int);
int addresstype(int a[],int);
int main()
{
int n,i,result,array[100];
cout<<"enter a value:";
cin>>n;
cout<<"enter "<<n<<" numbers"<<endl;
for(i=0;i<n;i++)
cin>>array[i];
result=pointertype(array,n);
cout<<"Sumo of the array using pointertype:"<<result<<endl;
result=addresstype(array,n);
cout<<"Sumo of the array using addresstype:"<<result<<endl;
return 0;
}
int pointertype(int *p,int n)
{
int i,sum=0;
for(i=0;i<n;i++)
sum=sum+p[i];
return sum;
}
int addresstype(int a[],int n)
{
int i,sum=0;
for(i=0;i<n;i++)
sum=sum+a[i];
return sum;
}

screenshot of the program main.cpp #include iostream» 2 using namespace std; 3 int pointertype(int *,int); 4 int addresstype (int al],int); 5 int main(20 int pointertype(int p,int n) int i, sum-0; for(i-0;i<n;i++) sum-sum p[i]; return sum; 23 24 25 26 27 int addresstype(int

output:

enter a value: 5 enter 5 numbers 1 2 3 4 5 Sumo of the array using pointertype:15 Sumo of the array using addresstvpe: ..Prog

Add a comment
Know the answer?
Add Answer to:
Write a C++ program which inputs an array of integers from user then pass array pointer...
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
  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • Write a C++ function that takes a pointer to an array of integers as a parameter...

    Write a C++ function that takes a pointer to an array of integers as a parameter and return the number of prime integers in the array. Write main() program to test the function.

  • Write a C program that prompts the user to enter a series of integers that represent...

    Write a C program that prompts the user to enter a series of integers that represent a coded message. I have given you the decoder program so that you can see how it is written using array notation. Your assignment is to convert the code to a program that uses only pointers and pointer math. Your program must use pointer notation and pointer math (i.e. no array index notation other than in the declaration section, no arrays of pointers and...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • 1. Palindrome Write a program that prompts the user for a positive integer number and output whet...

    Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • Pointer tasks: ( In C++ ) 1. Write a program to store the address of a...

    Pointer tasks: ( In C++ ) 1. Write a program to store the address of a character variable and a float variable. • Print the address of both variables. • Print the values of variable using dereference operator. • Add 2 in float value using pointer. • Print address of character variable using reference operator. 2. Write a program that takes 5 elements in an array and print them in reverse order using pointers. 3. Write to program that takes...

  • Write a program which will take a list of integer number from the user as input...

    Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

  • write the program in c++ Pointen & A???ys: Write u function that is passed a pointer...

    write the program in c++ Pointen & A???ys: Write u function that is passed a pointer to a float array, and the size the array as an int. The function should return a pointer to the maximum element in the array The function should be: int *maxp(float* ap, int size) Write a main() program to lest the function with different input arrays. Grading Criteria (1 point each): Uses cin/cout correct function definition prompts user for input, reads it in correct...

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