Using C++ write a function AllSame(a,n) that returns 1 if all components of the positive integer array a[0 .. n-1] have the same sums of digits; otherwise it returns 0. E.g. the array a [ ] = {17, 242, 62, 35, 431, 8} has the same sums of digits and AllSame(a, 5) returns 1.
#include <iostream>
using namespace std;
// sumDigits function takes n as input and returns the sum of digits in n
int sumDigits(int n){
if(n > 0){
return (n%10) + sumDigits(n/10);
}
else{
return 0;
}
}
// Function AllSame returns 1 if all components of the positive integer array a[0 .. n-1]
// returns 0 otherwise
int AllSame(int a[], int n){
int sum = sumDigits(a[0]);
for(int i=1;i<n;i++){
if(sumDigits(a[i])!=sum){
return 0;
}
}
return 1;
}
int main(){
int a [ ] = {17, 242, 62, 35, 431, 8};
cout<<AllSame(a, 5)<<endl;
return 0;
}

1
Using C++ write a function AllSame(a,n) that returns 1 if all components of the positive integer...
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].
write a recursive function that returns true if the digits of a positive integer are in increasing order ; otherwise, the function returns false. Also write a program to test your function.
1)
a) Write MATLAB function that accepts a positive integer
parameter n and returns a vector containing the values of the
integral (A) for n= 1,2,3,..., n. The function must use the
relation (B) and the value of y(1). Your function must preallocate
the array that it returns. Use for loop when writing your code.
b) Write MATLAB script that uses your function to calculate the
values of the integral (A) using the recurrence relation (B), y(n)
for n=1,2,... 19...
Positive and negative: Return these four results using C++ reference parameter Write a function, named sums(), that has two input parameters; an array of floats; and an integer, n, which is the number of values stored in the array. Compute the sum of the positive values in the array and the sum of the negative values. Also count the number of positives and negative numbers in each category. Write a main program that reads no more than 10 real numbers...
Write a function that returns the number of digits in an integer using the following header: int getSize(int n) For example, getSize(45) returns 2, getSize(3434) returns 4, getSize(4) returns 1, and getSize(0) returns 1. Write a test program that prompts the user to enter an integer and displays its size.
Using python Write a Python function called sgm that requests a positive integer n and returns the series geometric mean of the numbers 1,2,3, . . . n. For example sgm(5) = (5 x 4 x 3 x 2 x 1)1/5 = (120) 1/5 = 2.605 . Write the program so that a user is requested for a positive integer and program prints the series geometric mean of the integer. Example execution: Enter number: 5 series geometric mean of 5...
Using C++
Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...
Write a recursive function named arithmeticSum that takes a positive integer parameter n and returns the sum of the integer numbers from 1 to n Please write in C++
USING C++: Write a function that will print out all the factors of a given positive integer N. The factors of N are all the numbers that N is divisible by (i.e., x is a factor of N if N/x has remainder 0). The function prototype is provided below. E.g. factors(12) will print out 1, 2, 3, 4, 6, 12. void factors(int);
Write a Haskell function integerSqrt that returns the integer square root of a positive integer n. (The integer square root is defined to be the largest integer whose square is less than or equal to n, i.e. the result of integerSqrt 15 is 3.). integerSqrt :: Integer -> Integer