Elements Of An Array Converted To Absolute Values By Using Recursion

  • Uploaded by: Al Fredo
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Elements Of An Array Converted To Absolute Values By Using Recursion as PDF for free.

More details

  • Words: 191
  • Pages: 2
/* Reinforcement 4.3 give an algorithm that uses tail recursion to convert every element in an integer array A into its absolute vale. */ #include #include using namespace std; int absolute(int Arr[], int size) // the function { if(size < 0) return 0; else { if (Arr[size-1] < 0) { Arr[size-1] = abs(Arr[size-1]); absolute(Arr,size-1); } } } int main() {

//driver programme

int* Array; int size; cout <<"how many values " << endl; cin >> size;

Array = new int[size]; int val; cout << "please input the values "<< endl; for (int i =0; i< size; i++) { cin >> val; Array[i]= val; } absolute(Array,size);

for (int i =0; i< size; i++) { cout << "their absolute values are " <
}

Note: A recursion is descibed to be a tail recursion if the last action of the recuresive funtion is a recursive call.

Disclaimer: The question presented above is the property of john wiley& sons inc. However the code is solely a humble effort from my sideā€¦ Have fun! If you have any comments please do contact me. My code is open for critique and review.

Related Documents


More Documents from "gbland"