assignment-p-05.c¶
Problem Statement
Write a C program that defines an array of integers, and includes a user-defined function named reverseArray with the signature void reverseArray(int arr[], int size);. The function should reverse the elements of the array.
Metadata¶
| Property | Detail |
|---|---|
| Author | Amit Dutta amitdutta4255@gmail.com |
| Date | 12 Dec 2025 |
| License | MIT License (See the LICENSE file for details) |
| Difficulty | Beginner (index: 2 / 10) |
Concepts¶
Beta Feature
This concept detection system is still in beta and may occasionally show incorrect or incomplete results.
- Recursion
- Array
- Sorting (possible)
- Iteration
Actions¶
You can print or save this file by opening Raw and using your browser.
Source Code¶
#include <stdio.h>
void inputArray(int[], int);
void reverseArray(int[], int);
int main()
{
int size;
printf("How many element do you want to add: ");
scanf("%d", &size);
int arr[size];
inputArray(arr, size);
reverseArray(arr, size);
return 0;
}
void inputArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
{
printf("Enter element %d: ", i + 1);
scanf("%d", &arr[i]);
}
}
void reverseArray(int arr[], int size)
{
int i, j, temp;
printf("\nBefore Reverse: \n");
for (i = 0; i < size; i++)
{
printf("Position: %d, Value: %d\n", i, arr[i]);
}
for (i = 0, j = size - 1; i < j; i++, j--)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
printf("\nAfter Reverse: \n");
for (i = 0; i < size; i++)
{
printf("Position: %d, Value: %d\n", i, arr[i]);
}
}
Explanation¶
Explain with AI
Copy the prompt below and paste it into any AI assistant.
You are explaining a C programming code to a beginner.
STRICT RULES:
- Only use the given code. Do NOT assume anything not present.
- Do NOT add extra examples.
- Keep explanation clear and short.
- If something is unclear, say "Not clear from code".
- Follow the exact format below. Do NOT change headings.
FORMAT:
[START]
## What it does
(Explain the overall purpose in 1-2 sentences)
## Step-by-step
(Explain how the code works in steps, simple language)
## Key Concepts
(List concepts like loop, condition, function, etc.)
## Notes
(Mention any limitations, errors, or assumptions)
[END]
CODE (assignment-p-05.c):
#include <stdio.h>
void inputArray(int[], int);
void reverseArray(int[], int);
int main()
{
int size;
printf("How many element do you want to add: ");
scanf("%d", &size);
int arr[size];
inputArray(arr, size);
reverseArray(arr, size);
return 0;
}
void inputArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
{
printf("Enter element %d: ", i + 1);
scanf("%d", &arr[i]);
}
}
void reverseArray(int arr[], int size)
{
int i, j, temp;
printf("\nBefore Reverse: \n");
for (i = 0; i < size; i++)
{
printf("Position: %d, Value: %d\n", i, arr[i]);
}
for (i = 0, j = size - 1; i < j; i++, j--)
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
printf("\nAfter Reverse: \n");
for (i = 0; i < size; i++)
{
printf("Position: %d, Value: %d\n", i, arr[i]);
}
}