Computer Science, asked by kasho7654321, 1 month ago

Write a C++ program
to find out maximum & minimum Some values using line function
Test Data: Input vales
35, 65, 20,25 and 11.
Expecteed outputs Numbers of values you want to input 5 values.
Minimum value is 11
Maximum value is : 65​

Answers

Answered by anindyaadhikari13
4

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎‎de is writtten in C++.

#include <stdio.h>

int main() {

   int i,n,max,min;

   printf("How many elements? ");

   scanf("%d",&n);

   int a[n];

   printf("Enter the numbers one by one.\n");

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

       printf("a[%d] = ",i);

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

   }

   max=a[0];

   min=a[0];

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

       if(a[i]>max)

           max=a[i];

       if(a[i]<min)

           min=a[i];

   }

   printf("The largest number is: %d\n",max);

   printf("The smallest number is: %d",min);

   return 0;

}

\texttt{\textsf{\large{\underline{Logic}:}}}

  • Accept n elements from the user and store them in array.
  • Assume that the largest number as well as the smallest number is present in first index.
  • Now, transverse through array elements.
  •    If any number is greater than max, store it in max.
  •    If any number is less than min, assign it to min.
  • Display the highest and lowest number.

See the attachment for output.

Attachments:
Similar questions