📌  相关文章
📜  国际空间研究组织 | ISRO CS 2013 |问题 47(1)

📅  最后修改于: 2023-12-03 15:07:34.033000             🧑  作者: Mango

ISRO CS 2013 - Question 47

Introduction

ISRO CS 2013 - Question 47 is a question related to programming and computer science. It is a part of the ISRO recruitment exam for computer science graduates. In this question, you are required to write a program to perform certain mathematical operations on a list of integers.

Problem Statement

Write a program to perform the following operations on a list of integers:

  1. Find the sum of all the integers in the list.
  2. Find the product of all the integers in the list.
  3. Find the maximum and minimum value in the list.

You can assume that the list contains at least one integer.

Solution

To solve this problem, we can use Python. Here is the code snippet:

def math_operations(lst):
    """
    This function performs mathematical operations on a list of integers.
    """
    # Initialize the variables for the sum and product.
    sum_lst = 0
    product_lst = 1
    
    # Initialize the variables for the maximum and minimum values.
    max_value = lst[0]
    min_value = lst[0]
    
    # Loop through the list to perform the operations.
    for num in lst:
        sum_lst += num
        product_lst *= num
        
        # Check if the current number is greater than the maximum value.
        if num > max_value:
            max_value = num
        
        # Check if the current number is smaller than the minimum value.
        if num < min_value:
            min_value = num
    
    # Return the results as a dictionary.
    return {
        'sum': sum_lst,
        'product': product_lst,
        'max': max_value,
        'min': min_value
    }

In the code above, we define a function called math_operations that takes a list of integers as a parameter. We then initialize variables to keep track of the sum and product of the list, as well as the maximum and minimum values.

We loop over each number in the list and perform the sum and product operations. We also check if the current number is greater than the current maximum value and update the max_value variable if necessary. Similarly, we check if the current number is less than the current minimum value and update the min_value variable.

Finally, we return the result as a dictionary containing the sum, product, maximum, and minimum values.

Conclusion

ISRO CS 2013 - Question 47 is a simple programming question that requires you to perform certain mathematical operations on a list of integers. With the use of a function and a few if statements, we can easily solve this problem in Python.