Question

2. Write a program that reads N integer numbers of array from the user and then...

2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()).

Here is sample output

Please enter number of elements: 4

Please enter the required numbers: 50 100 150 20

The entered numbers are: 50 100 150 20

Sum is : 320

Max is 150

by Mpsi ,sum and max to call subroutine and retrieve the results

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

#include <stdio.h>
void Read_Array(int arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}
void Display_Array(int arr[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
}
int Find_Max(int arr[],int n)
{
int i,max=arr[0];
for(i=0;i<n;i++)
{
if(max<arr[i])
max=arr[i];
}
return max;
}
int Calculate_Sum(int arr[],int n)
{
int i,s=0;
for(i=0;i<n;i++)
{
s=s+arr[i];
}
return s;
}

int main()
{
int n;
printf("Please enter number of elements: ");
scanf("%d",&n);
printf("Please enter the required numbers: ");
int arr[n];
Read_Array(arr,n);
printf("The entered numbers are: ");
Display_Array(arr,n);
printf("Sum is : %d\n",Calculate_Sum(arr,n));
printf("Max is : %d\n",Find_Max(arr,n));
  
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
2. Write a program that reads N integer numbers of array from the user and then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • Write a program that generates an array filled up with random positive integer number ranging from...

    Write a program that generates an array filled up with random positive integer number ranging from 60 to 100, and display it on the screen. After the creation and displaying of the array, the program displays the following: [R]everse [A]dd [S]earch E[xit] Please select an option:_ Then, if the user selects: - R (lowercase or uppercase): the program displays the reversed version of the array. - A (lowercase or uppercase): the program displays the sum of the elements of the...

  • Write a program that first reads an integer for the array size, then reads numbers into...

    Write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above the average. Make sure to include pointer syntax. Example output: Enter array size: 10 10 random numbers between 1 and 10 generated are: 2 8 5 1 10 5 9 9 3 5 The average is: 5.7 Number of items above the average = 4 C++ Code only.

  • Write a program that first reads an integer for the array size, then reads double values...

    Write a program that first reads an integer for the array size, then reads double values into the array, and displays the number of values greater than the average. Enter array size: 6 Enter a number: 1.1 Enter a number: 2.2 Enter a number: 3.4 Enter a number: 3.9 Enter a number: 5.5 Enter a number: 8.75 The number of values greater than the average is 2

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • Write a test program that prompt the user to enter seven numbers, stores them in an...

    Write a test program that prompt the user to enter seven numbers, stores them in an array list and do the following: 1. Displays its elements (numbers) in increasing order by invoking a method with the following header that sorts the array: public static void sort(ArrayList<Integer>list) 2. Write a method that returns and displays the sum of all numbers (elements) of the ArrayList. Using the following header: public static double sum(ArrayList<Integer>list) 3. Write a method that removes the duplicate numbers...

  • Please write a C++ program that will accept 3 integer numbers from the user, and output...

    Please write a C++ program that will accept 3 integer numbers from the user, and output these 3 numbers in order, the sum, and the average of these 3 numbers. You must stop your program when the first number from the user is -7. Design Specifications: (1) You must use your full name on your output statements. (2) You must specify 3 prototypes in your program as follows: int max(int, int, int); // prototype to return maximum of 3 integers...

  • Q#1 Write a C++ program that reads n integer values and stores them in an array...

    Q#1 Write a C++ program that reads n integer values and stores them in an array of maximum 20 integers. Read from the user a valid value of n (n should not exceed 20). After reading the n array elements find the maximum and minimum elements.

  • Write a C++ program that generates an array filled up with random positive integer number ranging...

    Write a C++ program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of the array. -R (lowercase or uppercase): the...

  • Write a program that reads an integer k from user and finds the number of elements...

    Write a program that reads an integer k from user and finds the number of elements that are divisible by k in the file assignment4.txt. A number n is divisible by k if n = kx for some integer x > 0. You can use the mod operator % to test for divisibility. The file assign4.txt has integer values in the range [0,100 ]. You should use end-of-file controlled loop for this problem. Sample execution is given below. Assume the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT