Answer to Question #219197 in C for Teja

Question #219197

Write a program to find the maximum difference between two adjacent numbers in an array of positive integers


1
Expert's answer
2021-07-20T15:28:53-0400
#include <stdio.h>


int max_difference(int a[], int n) {
    int max_dif = 0;
    int i;


    for (i=1; i<n; i++) {
        if (abs(a[i] - a[i-1]) > max_dif) {
            max_dif = abs(a[i] - a[i-1]);
        }
    }
    return max_dif;
}


int main() {
    int a[] = { 1, 5, 6, 1, 3, 44, 33, 98};
    int m = max_difference(a, sizeof(a) / sizeof(a[0]));
    printf("Maximum difference berween two adjacent numbers is %d\n", m);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS