Write a C program that finds the last and first element in the array.
Explanation:
Here is the code which takes the number of elements from the user and then the actual elements one by one.
After that, it prints the first and last element present in the array.
Code:
#include <stdio.h>
int main()
{
int n;
printf("Enter number of elements: ");
scanf("%d", &n);
int a[n];
printf("Enter elements: ");
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
printf("First element: %d\n", a[0]);
printf("Last element: %d\n", a[n-1]);
return 0;
}
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!
Get Answers For Free
Most questions answered within 1 hours.