34 lines
773 B
C
34 lines
773 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// This function should swap two givin indecies of an given array.
|
|
void SwapElements(int Array[], int a, int b)
|
|
{
|
|
int temp = Array[a];
|
|
Array[a] = Array[b];
|
|
Array[b] = temp;
|
|
|
|
}
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
// These lines turn the arguments from the commandline into ints
|
|
// We will talk about comandline parsing later
|
|
int ArrayCount = atoi(argv[1]);
|
|
int Element1 = atoi(argv[2]);
|
|
int Element2 = atoi(argv[3]);
|
|
|
|
int Array[ArrayCount];
|
|
|
|
for(int i = 0; i < ArrayCount; i++)
|
|
Array[i] = i+1;
|
|
|
|
// TODO: uncommend this line
|
|
SwapElements(Array, Element1, Element2); // This calles the funktion Swap Elements
|
|
|
|
for(int i = 0; i < ArrayCount; i++)
|
|
printf("Array[%d] = %d\n", i, Array[i]);
|
|
|
|
return 0;
|
|
}
|