Computer Science, asked by sahithibuddha495, 2 months ago

c program to return the difference between largest and smallest numbers from an array of positive integers

Answers

Answered by apurba2004vizag
5

Answer:

/ C program to find the smallest and largest element in an array. ​

int main() {

printf(“\nEnter the number of elements : “); scanf(“%d”,&n);

printf(“\nInput the array elements : “); ...

scanf(“%d”,&a[i]); ...

large=small=a[0]; ...

for(i=1;i<n;++i) ...

large=a[i];

Explanation:

Answered by aburaihana123
0

Answer:

The source code to determine the difference between the array's largest and smallest elements has mentioned below

Explanation:

Here, we'll make an integer array, calculate the difference between its largest and smallest entry, then display the result to the console.

#include<stdio.h>

void main(){

   int arr[100],a ,i, max, min, diff;

   printf("size of array is:");

   scanf("%d",&a);

   printf("enter the element ");

   for(i=0;i<a;i++){

   scanf("%d",&arr[i]);

   }

   printf("the array is \n");

   for(i=0;i<a;i++){

   printf("%d ",arr[i]);

   }

   printf("\n");

   min= max=arr[0];

   for(i=0;i<a;i++){

       if(max<arr[i]){

           max=arr[i];

       }

   }

   for(i=0;i<a;i++){

       if(min>arr[i]){

           min=arr[i];

       }

   }

   printf("%d is smaller then %d\n",min,max);

   diff=max-min;

   printf("the difference between them is %d",diff);

Final answer:

The difference between the array's largest and smallest components, then save the outcome in a diff variable.

#SPJ3

Similar questions