Java Array Exercises: Get the difference between the largest and smallest values in an array of integersLast update on December 13 2021 06:24:09 (UTC/GMT +8 hours)“finding the difference between the largest and smallest from a list of 5 numbers” Code Answerfind the largest and smallest numbers in a list whatever by Courageous Cod on Jun 03 2021 Comment 0 Add a Grepper Answer Whatever answers related to “finding the difference between the largest and smallest from a list of 5 numbers”
Whatever queries related to “finding the difference between the largest and smallest from a list of 5 numbers”
Difference between largest and smallest elements in an array in Java.Following are the steps to find the difference between the largest and smallest element in an array: Show
OutputC program to find the difference between the largest and smallest element in the arrayHere, we are going to learn how to find the difference between the largest and smallest element in the array in C programming language? Problem Solution: Here, we will create an array of integers and find the difference between the largest and smallest element of the array and print the result on the console screen. Program: The source code to find the difference between the largest and smallest element in the array is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully. // C program to find the difference between the // largest and smallest element in the array #include <stdio.h> int main() { int arr[] = { 10, 20, 70, 40, 50 }; int i = 0; int j = 0; int diff = 0; diff = arr[1] - arr[0]; for (i = 0; i < 5; i++) { for (j = i + 1; j < 5; j++) { if (arr[j] - arr[i] > diff) diff = arr[j] - arr[i]; } } printf("Difference is: %d\n", diff); return 0; }Output: Difference is: 60Explanation: Here, we created an array arr with 5 elements. And, we also created three variables i, j, diff that are initialized with 0. Then we find the difference between the biggest and smallest elements of the array and store the result into a diff variable. After that, we printed the result on the console screen. C One-Dimensional Array Programs » C program to segregate 1's and 0's in the array C program to print the square of array elements ADVERTISEMENT Preparation Aptitude Questions MCQs Find Output Programs What's New
ADVERTISEMENT Top Interview Coding Problems/Challenges!
Comments and Discussions! Please enable JavaScript to view the comments powered by Disqus. ADVERTISEMENT |