This is easier to achieve using C++ than C, because we can make use a single template function that can cater for arrays of any type in a type-safe manner. In C, we must use macro trickery to cater for different array types, but macros are not type-safe. However, if we limit ourselves to arrays of integers, we can provide a concrete implementation:
void swap_oddeven (int* p, size_t size) {
if (size<2) return;
for (size_t index=1; index<size; index+=2) swap (p[index], p[index-1]);
}
Use the following function:
void exchange_odd_even (int* arr, size_t len) {
for (int i=1; i<len; i=i+2) swap (arr[i-1], arr[i]);
}
Note that we traverse the array from index 1 rather 0, incrementing in steps of 2. This is because index 1 is an even element (the 2nd element) and for every even element in the array we can guarantee there has to be a preceding odd element to swap with. Doing it this way means we don't need to cater for the special case where 'len' is odd and the final odd element has no even element to swap with.
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
Reference:cprogramming-bd.com/c_page1.aspx# array programming
To write a C++ program to display the student details using class and array of object.
How to write a program for mouse in microprocessor?
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.Usually one element at a time. If you want to process all elements of an array, you write a loop.
import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }
Reference:cprogramming-bd.com/c_page1.aspx# array programming
To write a C++ program to display the student details using class and array of object.
How to write a program for mouse in microprocessor?
Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.
int sumArray(int N, int* A) { int sum = 0; do sum += A[N-1] while (N-- > 1); return sum; }
write an assembly language program to find sum of N numbers
array type
int findMax(int *array) { int max = array[0]; for(int i = 1; i < array.length(); i++) { if(array[i] > max) max = array[i] } return max; }
maxValue = function (array) {mxm = array[0];for (i=0; i<array.length; i++) {if (array[i]>mxm) {mxm = array[i];}}return mxm;}; i don't know
public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i < array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }