Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using c, Write a function called reverse_numbers. The function is passed an arra

ID: 3750462 • Letter: U

Question

Using c, Write a function called reverse_numbers. The function is passed an array of ints (and of course its length as a 2nd parameter). The function should reverse the ordering of the numbers in the array. Here is its prototype:
void reverse_numbers(int nums[], int len); Using c, Write a function called reverse_numbers. The function is passed an array of ints (and of course its length as a 2nd parameter). The function should reverse the ordering of the numbers in the array. Here is its prototype:
void reverse_numbers(int nums[], int len); array. Here is its prototype:
void reverse_numbers(int nums[], int len);

Explanation / Answer

function:

void reverse_numbers(int nums[], int len)

{

                int left, right, temp;

                left = 0;

                right = len - 1;

                while(left<right)

                {

                                temp = nums[left];

                                nums[left] = nums[right];

                                nums[right] = temp;

                                left++;

                                right--;

                }

}

C Program:

#include <stdio.h>

#include<math.h>

void reverse_numbers(int nums[], int len)

{

                int left, right, temp;

                left = 0;

                right = len - 1;

                while(left<right)

                {

                                temp = nums[left];

                                nums[left] = nums[right];

                                nums[right] = temp;

                                left++;

                                right--;

                }

}

int main() {

                int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

                reverse_numbers(a, 10);

                int i;

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

                printf("%d ", a[i]);

                return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote