31 lines
756 B
C
31 lines
756 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
// This function should swap two given indices of an given array.
|
||
|
void SwapElements(/*TODO define the parameters*/)
|
||
|
{
|
||
|
// TODO: write the code to swap to elements
|
||
|
}
|
||
|
|
||
|
int main(int argc, const char *argv[])
|
||
|
{
|
||
|
// These lines turn the arguments from the command-line into ints
|
||
|
// We will talk about command-line 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: uncomment this line
|
||
|
//SwapElements(Array, Element1, Element2); // This calls the function Swap Elements
|
||
|
|
||
|
for(int i = 0; i < ArrayCount; i++)
|
||
|
printf("Array[%d] = %d\n", i, Array[i]);
|
||
|
|
||
|
return 0;
|
||
|
}
|