Write a function named numPerfect that takes as parameters:
an array of integer scores between zero and 100 (inclusive)
the size of the array
and returns the number of perfect scores in the array.
Also write a main function that creates and initializes an array of ints (in the appropriate range), calls the function with that array, and prints out the return value.
#include <iostream>
#include <iostream>
#include <iomanip>
using namespace std;
// Function Declarations
bool is_perfect(int num);
int numPerfect(int arr[], int size);
int main()
{
// Declaring varaibles
int i = 0, size, num, tot;
// Getting the size of an array
cout << "Enter the size of an array :";
cin >> size;
// Creating integer array dynamically based on size
int* arr = new int[size];
/* Getting the numbers entered by the user
* and populate those values into an array
*/
while (i < size)
{
cout << "\nEnter the number#" << i + 1 <<
":";
cin >> num;
if (num < 0 || num > 100)
{
cout << "Invalid .Number must be between 0-100" <<
endl;
continue;
}
else
{
arr[i++] = num;
}
}
tot = numPerfect(arr, size);
cout << "Total No of Perfect Numbers in the array :" <<
tot << endl;
return 0;
}
int numPerfect(int arr[], int size)
{
int count = 0;
for (int i = 0; i < size; i++)
{
if (is_perfect(arr[i]))
{
count++;
}
}
return count;
}
/* Function implementation which checks
* whether the user entered number is perfect or not
*/
bool is_perfect(int num)
{
// Declaring the variable
int sum = 0;
for (int i = 1; i < num - 1; i++)
{
if (num % i == 0)
sum += i;
}
/* if the user entered number is equal to the
* sum value the number is perfect number
*/
if (sum == num)
return 1;
else
return 0;
}
____________________
Output:
_____________Could you rate me well.Plz .Thank
You
Write a function named numPerfect that takes as parameters: an array of integer scores between zero...
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...
Write a function named findTarget that takes three parameters: - numbers, an array of integers - size, an integer representing the size of array - target, a number The function returns true if the target is inside array and false otherwise
In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...
a) Write a function that takes as input 2 parameters, an array and its size (both ints) and returns the max. Include the driving (main program also. To pass an array to a function, do the following: return_type my_function(int my_array[], int size) b) Write a function that does the above but can contain duplicate numbers and is capable of removing them. Scan in input. Note you may need the sizeof( ) function which is one of the standard libraries.Thus you...
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...
Write a JAVA PROGRAM with function named getData() that takes a matrix A and an integer "row" as input parameters and returns an array containing all elements in the given row of A.
Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...
Given an array and a starting position write a function replaceFromN, that takes an integer array 'array', the size of the array size and a starting positions 'n' as parameters and replaces the elements starting from that index onward with the sequence 1,2,3,... The function returns nothing. void replaceFromN(int array[], int size, int n) For example, given array= {15,12,4,9,2,3} n =2 the function should modify array to be {15,12,1,2,3,4}
Write a C program that deal with employees’ salaries in a company, as follows: Define an integer array named salaries of size 100 Initialize all array elements with zeros Fill all array elements with random numbers within a range of 350 until 3000 (all inclusive) by using built-in-function rand() and srand() Develop the following functions and call them from the main program: avgSalary(), a function that receives the array and its size as parameters and returns the average salary in...
Python Write a function (named largest_of_three) that takes three parameters and returns the largest. You can assume the parameters are either floats or ints.