Computer Science, asked by akashanandnair7777, 4 months ago

please help me with the answer​

Attachments:

Answers

Answered by anindyaadhikari13
2

Required Answer:-

Question:

  • Write a program to input a list of elements and display the largest and smallest element without using max() and min() function.

Solution:

This is written in Python.

n=int(input("How many elements?? "))

print("Enter them...")

a=[]

for i in range(n):

a.append(int(input("Enter >> ")))

max=a[0]

min=a[0]

for i in a:

if i>max:

 max=i

if i<min:

 min=i

print("Largest Number:  ",max)

print("Smallest Number:  ",min)

Algorithm:

  1. START
  2. Accept n elements in the list.
  3. Assume that the largest element and the smallest element is in the first position in the list. Then, iterate through the list. If any number is greater than the largest number,then assign the largest number variable with that value. Similarly, if any number is smaller than the smallest number, assign the value in min variable.
  4. Display the result.
  5. STOP.

Request:

  • If you are using brainly from web, see the program from attachment as indentation might not be shown properly on web.
  • Link: https://brainly.in/question/34280500

Refer to the attachment for output ☑.

Attachments:
Similar questions