Using C programming
Write a function that reverses the elements of an array of integers so that the first becomes the last. Hint use a temporary variable for swapping values. Test with an odd and even number of elements
#include <stdio.h>
#include <malloc.h>
void reverse_array(int arr[], int size) {
int i, temp;
for (i = 0; i < size/2; ++i) {
temp = arr[i];
arr[i] = arr[size-i-1];
arr[size-i-1] = temp;
}
}
void print_array(int arr[], int size) {
int i;
for (i = 0; i < size; ++i) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main() {
int arr[] = {4, 9, 1, 5, 8, 2};
printf("Original array: ");
print_array(arr, 6);
reverse_array(arr, 6);
printf("Reversed array: ");
print_array(arr, 6);
int arr1[] = {2, 9, 6, 1, 4};
printf("\nOriginal array: ");
print_array(arr1, 5);
reverse_array(arr1, 5);
printf("Reversed array: ");
print_array(arr1, 5);
return 0;
}
Using C programming Write a function that reverses the elements of an array of integers so...
C programming Write a function that accepts an array of integers as an input, and output the sum of all values and the multiplication of all values. e.g. Suppose that the array contained the following values: 1 2 3 -4 5. The function should calculate and output the sum of values (i.e. 1+2+3+(-4)+5=7) and the multiplication of all values (i.e. 1*2*3*-4*5=-120). Start by carefully writing the function prototype - put some thought into this. Think about the good programming habits,...
Write array methods that carry out the following tasks for an array of integers by completing the ArrayMethods class below. For each method, provide a test program. public class ArrayMethods { private int[] values; public ArrayMethods(int[] initialValues) { values = initialValues; } public void swapFirstAndLast() { . . . } public void shiftRight() { . . . } .. . } a. Swap the first and last elements in the array. b. Shift all elements to the right by one...
Write a function called median that returns the median entry in a 1-dimensional array of integers. For example, if we have an array a={3,4,5,1,6}; then the median entry of this array a is 4. You need to sort the array a first, to get {1,3,4,5,6}, then find the entry in the middle position. If the array size is even, it means that array has even number of elements. For example, a={3,2,4,1}, then first sort it, a becomes {1,2,3,4}, then the...
Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...
C programming Write a function that goes through all elements of an array of size n, and output the minimum and maximum values using pointers. Since C functions can only return one value, you must use pointers to output the minimum and maximum values from the function. You are not expected to print the values on the screen. Note: you will be assessed on the functionality and the coding style.
Write a Program in C language for:
1. Create a C program to read 7 integers and store them in an array. Next, the program is to check if the array is symmetric, that is if the first element is equal to the last one, the value of the second one is equal to the value of the last but one, and so on. Since the middle element is not compared with another element, this would not affect the symmetry...
IN C++ Write a function numberOfOddNumbers that takes an array of integers and its size (length) as parameters and then returns the number of the odd numbers found in the array. For example, if an array called list stores the following values: int list []= { 1,1, 8,6,9,4,3,9595,0 }; Then the call of numberOfOddNumbers (list,9) should return 5. If instead, the list had stored these values: int list2[] = { 2, 4, 6, 8, 10, 208 }; Then the call...
Write a program using C in Microsoft visual studios. Write a function that receives an array of integers and the array length and prints one integer per line (Hint: Use \n for a line break). Left align all of the integers and use a field width of 10. Populate an array of 10 elements from the user and pass the array and its length to the function.
Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) – Which calls the private recursive method, passing the array parameter and which two array elements should be swapped. - private static void reverseRecursive(int [] array, int startIndex, int endIndex) – Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time,...
please use c++ language 1. Request three different integers from the console. a) Write a swap function that swaps two integer values. b) Write a sort function which accepts three integers as input then sorts them from largest to smallest using the swap function. c) Output the integers before and after sorting. Example 1 Output (input in bold italics) Enter three different integers: 3 2 4 3 2 4 4 3 2 Example 2 Output (input in bold italics) Enter...