Question

Write a C++ program that does the following : 1. Accepts array size from the keyboard....

Write a C++ program that does the following :

1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive .

2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200.

3. Display the generated array.

4. Write a recursive function that displays the array in reverse order .

5. Write a recursive function that returns a result of a number raised to a power. The function should take two arguments, the number to be raised to the power is the last number in array and the power is 2.

6. Write a recursive function that displays squares of integers in ascending order, starting from 1 to the first number in the array.

7. Write a recursive function that displays the second number in the array vertically .

8. Write a recursive function that returns true if the digits of the third number in the array is in increasing order ; otherwise , the function returns false.

9. Write a recursive function that takes the fourth number in the array and returns the numbers with the digits reversed.

10. Write a recursive function that determines and returns true or false to whether or not the fifth number in the array is a prime number

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

#include<iostream>
#include<cstdlib>
using namespace std;
void displayReverse(int a[],int n)
{
    if(n<0)
    return ;
    else
    {
    cout<<"\n"<<a[n];
    displayReverse(a,(n-1));
}
    }
   
    int recPower(int base,int a)
    {
        if(a!=0)
        return(base*recPower(base,(a-1)));
        else
        return 1;
    }
int main()
    {
    srand(time(NULL));
    int size,a[15];
    while(1)
    {
    cout<<"\nEnter size of array between 5 to 15: ";
        cin>>size;
        if(size>=5 &&size<=15)
        break;
        else
        cout<<"\nInput not in the range!Try again";
}
    int lower =10;
    int upper = 200;
    for(int i=0;i<size;i++)
    a[i]=(rand() % (upper - lower + 1)) + lower;
    cout<<"\nThe randomly generated array :";
    for(int i=0;i<size;i++)
    cout<<a[i]<<"\n ";
    cout<<"\nThe array in reverse order is : ";
    displayReverse(a,size-1);
   
cout<<endl;
int pow=recPower(a[size-1],2);
        cout<<a[size-1]<<" to the power 2 is "<<pow;
}

CppDroid project_jan25c.cpp Navigator Editor 1 #include<iostream> 2 #include<cstdlib> 3 using namespace std; 4 void displayReCppDroid project_jan25c.cpp Navigator Editor int recPower(int base, Int a) if(a!=0) return(base*recPower(base, (a-1))); elseCppDroid terminal Stopped Enter size of array between 5 to 15: 6 The randomly generated array : 74 53 111 43 192 176 The arra

Sorry dude... Time up.. Tried to solve as much questions as I could in the given time slot..

Please repost the remaining questions again.. Will surely solve.

Also please upvote... Thanks...

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that does the following : 1. Accepts array size from the keyboard....
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
  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Write a c++ program that does the following Create an integer array of size 30. Assign...

    Write a c++ program that does the following Create an integer array of size 30. Assign -1 to each location in the array indicating that the array is empty. Populate half of the array with random integer values between 100 and 500 inclusive. Use the following formula in order to hash and store each number in its proper position/location. Generated Number Table Size: Should a collision occurs, use linear probing to find next available position location. Use the following probing...

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • in a program, write a function that accepts three arguments: an array, the size of the...

    in a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n.

  • Write a C++ program that does the following : Accepts a positive integer ( n )...

    Write a C++ program that does the following : Accepts a positive integer ( n ) from the keyboard . Create an character array of size n. Using a random number generator, populate the array with characters between 33 – 126. Create 7 individual functions and perform the following 1. In the first function: display elements of the array. Display the first 20 elements If the size is > 20 2. In the second function : Using recursion, Search for...

  • Problem: Write a C++ program that does the following : Accepts a positive integer ( n...

    Problem: Write a C++ program that does the following : Accepts a positive integer ( n ) from the keyboard . Create an character array of size n. Using a random number generator, populate the array with characters between 33 – 126. Create 7 individual functions and perform the following In the first function: display elements of the array. Display the first 20 elements If the size is > 20 In the second function : Using recursion, Search for a...

  • c++ Write a function that uses recursion to raise a number to a power. The function...

    c++ Write a function that uses recursion to raise a number to a power. The function should accept two arguments: the number to be raised and the exponent. Assume that the exponent is a nonnegative integer. Demonstrate the function in a program. Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will...

  • using c++ Write a function that returns true if a given integer array is sorted(in ascending...

    using c++ Write a function that returns true if a given integer array is sorted(in ascending order) and false if it is not. The function should perform no more than "size" comparisons. bool isSorted(int A[], int size);

  • (C++) Write a function that accepts an int array and the array’s size as arguments. The function...

    (C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...

  • 1. Write a function named “areFirstTwoTheSameAsTheLastTwo” that accepts an array of integers, its size and return...

    1. Write a function named “areFirstTwoTheSameAsTheLastTwo” that accepts an array of integers, its size and return true if the first two numbers in the array are the same as the last two numbers in the array. It returns false otherwise. If the array has less than 4 elements, it always returns false. For example, this array of {10, 20, 30, 40, 10, 20} or {10, 20, 10, 20} will return true but this array of {10, 20, 20, 10} or...

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