“Find Differences of Adjacent Array Elements Using RR[i+1] − RR[i] Pattern in C”
C
Medium
3 views
Problem Description
Array contains numbers, you need to find the difference of adjacent elements and store it in a new array - how will you implement the pattern RR[i+1] - RR[i]?
Official Solution
#include <stdio.h>
int main() {
int RR[] = {10, 15, 25, 40, 55};
int size = sizeof(RR) / sizeof(RR[0]);
int diff[size - 1]; // new array to store differences
// Apply RR[i+1] - RR[i] pattern
for (int i = 0; i < size - 1; i++) {
diff[i] = RR[i + 1] - RR[i];
}
printf("Differences of adjacent elements:n");
for (int i = 0; i < size - 1; i++) {
printf("%d ", diff[i]);
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!