Question

In: Computer Science

• Write a C++ program to find the largest umber, smallest number and sum of all...

• Write a C++ program to find the largest umber, smallest number and sum of all the element of a given array of 20 integers

• Note

− Declare array to 20 numbers

− Input values for 20 array elements

− Find largest number

− Find smallest number

− Find sum of all numbers

• Display the results

Solutions

Expert Solution

C++ program:

#include <iostream>
using namespace std;

int main()
{
int i, N,s;
float a[20];

N=20;
for(i = 0; i < N; ++i)
{
cout << "Enter Number " << i + 1 << " : ";
cin >> a[i];
}

//Largest number
for(i = 1;i < N; ++i)
{

if(a[0] < a[i])
a[0] = a[i];
}
cout << "Largest Number = " << a[0];
cout<<"\n";
  
//smallest number
for(i = 1;i < N; ++i)
{

if(a[0] > a[i])
a[0] = a[i];
}
cout << "Smallest Number = " << a[0];
cout<<"\n";
  
//sum of all the elements
for(i = 1; i < N; ++i)
{
s += a[i];
}
cout << "Sum of all numbers= " << s;

return 0;
}

Output:


Related Solutions

1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input.
1. Write a program that computes the smallest and largest of a set of values that...
1. Write a program that computes the smallest and largest of a set of values that are stored in an array. Ask the user for the set size (and hence the array size). Populate the array with user input. (Java language)
Please write a C++ program to find the largest number among three numbers using nested if...else...
Please write a C++ program to find the largest number among three numbers using nested if...else statements You need to prompt the user to enter three integer numbers from the keyboard, and then display the largest number among the three. Please create a function to find the largest number among three numbers, and call the maxAmongThree function in the main function.
Write a Java program to get the difference between the largest and smallest values in a...
Write a Java program to get the difference between the largest and smallest values in a user inputed array of integers. The length of the array must be 1 and above
Find the largest and smallest element of a linked list, print total of all elements and...
Find the largest and smallest element of a linked list, print total of all elements and find out the average. Code needed in java
Write a C++ program to find K largest elements in a given array of integers. For...
Write a C++ program to find K largest elements in a given array of integers. For eeample, if K is 3, then your program should ouput the largest 3 numbers in teh array. Your program is not supposed to use any additional array.
Write two algorithms to find both the smallest and largest numbers in a list of n...
Write two algorithms to find both the smallest and largest numbers in a list of n numbers. In first algorithm, you simply write one loop to find the minimum and maximum. So there will be 2(n - 1) comparisons. In second algorithm, you try to find a method that does at most 1.5n comparisons of array items. Determine the largest list size (i.e., n) that Algorithm 1 can process and still compute the answer within 60 seconds. Report how long...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3!...
-Write a program in C++: • to find the sum of the series 1! /1+2! /2+3! /3+4! /4+5! /5 using the function1, • to convert decimal number to binary number using the function2, • to check whether a number is a prime number or not using the function3, • to check whether two given strings are an anagram using the function4. important must do in (Multi-Filing) of c++
Write a program in C++ to read 10 numbers from keyboard and find their sum, average,...
Write a program in C++ to read 10 numbers from keyboard and find their sum, average, maximum and minimum
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT