Search
 
SCRIPT & CODE EXAMPLE
 

C

function that reverses the content of an array of integers.

#include <stdio.h>
 
// Function to print contents of an array
void print(int arr[], int n)
{
    for (int i = 0; i < n; i++) {
        printf("%d ", arr[i]);
    }
}
 
// Function to reverse elements of an array
void reverse(int arr[], int n)
{
    int aux[n];
 
    for (int i = 0; i < n; i++) {
        aux[n - 1 - i] = arr[i];
    }
 
    for (int i = 0; i < n; i++) {
        arr[i] = aux[i];
    }
}
 
int main(void)
{
    int arr[] = { 1, 2, 3, 4, 5 };
    int n = sizeof(arr)/sizeof(arr[0]);
 
    reverse(arr, n);
    print(arr, n);
 
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: add last in list c 
C :: shortest job first 
C :: get multiple c 
C :: find a substring within a string in c and return the index 
C :: sue murry 
C :: sadsa 
C :: panagram in c 
C :: escaping characters in hibernate queries 
C :: Calculate the area of a circle and modify the same program to calculate the volume of a cylinder given its radius and height. 
C :: string compare in c 
C :: fscanf stops at space 
C :: is 0 true or false 
C :: c addition 
C :: Dividing canvas in live2d 
C :: bucket sort 
C :: arduino ip to string 
C :: calendar in c 
Dart :: flutter keyboard causes overflow 
Dart :: flutter get millis time 
Dart :: Waiting for another flutter command to release the startup lock... 
Dart :: flutter listtile leading and title space 
Dart :: flutter checkbox 
Dart :: taskkill dart 
Dart :: toast flutter 
Dart :: flutter lock orientation 
Dart :: How do I rotate widget in flutter? 
Dart :: sort list descending from spesific maps key in dart 
Dart :: how to load gif in flutter 
Dart :: how to give bottom padding in Listview in flutter 
Dart :: after build flutter 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =