// C code to determine if there exist a subset such that
sum of elemnets of subset is half of sum of total
set
#include <stdio.h>
#include <stdbool.h>
bool partitionSum(int array[], int size, int subsetSum)
{
int i,j;
// result[i][j] = 1 if there is a array[0..j-1] with sum = i
bool result[subsetSum+1][size+1];
// If subsetSum is 0, then answer is 1
for (i = 0; i <= size; i++) result[0][i] = 1;
// If subsetSum is not 0 and array is empty, then answer is
0
for (i = 1; i <= subsetSum; i++)
result[i][0] = 0;
// filling the result table
for (i = 1; i <= subsetSum; i++)
{
for (j = 1; j <= size; j++)
{
result[i][j] = result[i][j-1];
if (i >= array[j-1])
result[i][j] = result[i][j] || result[i - array[j-1]][j-1];
}
}
// return the value of subsetSum,size in result table
return result[subsetSum][size];
}
int main()
{
int i,sum = 0;
int array1[] = {5, 10, 6, 8, 1};
int n = sizeof(array1)/sizeof(array1[0]);
for (i = 0; i < n; ++i)
{
sum = sum + array1[i];
}
int subsetSum = sum/2;
if (partitionSum(array1, n, subsetSum) == 1)
printf("Yes, Subset exist\n");
else
printf("Subset does not exist\n");
// output: Yes, Subset exist
sum = 0;
int array2[] = {1, 5, 7, 34, 76, 54, 23, 19, 22, 81, 44, 77, 29,
40, 11, 42, 43, 31, 57, 61};
n = sizeof(array2)/sizeof(array2[0]);
for (i = 0; i < n; ++i)
{
sum = sum + array2[i];
}
subsetSum = sum/2;
if (partitionSum(array2, n, subsetSum) == 1)
printf("Yes, Subset exist\n");
else
printf("Subset does not exist\n");
// output: Yes, Subset exist
return 0;
}
Hi please help with this program C++ language thanks Write a recursive solution to solve the...
Program has to be in C# language
Write a computer program that takes two sets (let the user determine the cardinality of each set and enter them manually) and calculates the following operations: Union Intersection Difference (set1 - set2) Cartesian product (set2 X set1) Check whether set2 is a subset of set1 or set1 is a subset of set2 Find the powerset of set1 and print out its elements and cardinality
write a function to generate test data. The common-lisp function (random n) will return a random number in the range zero to n. there is a problem of number partitioning. Given a set of integerts, the task is to divide them into two mutually exclusive and collectively exhaustive subsets, so that the sums of the numbers in each subset are as nearly equal as possible. For example, given the set (1 4 9 16 25), an optimal partition divides the...
Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a single BIG integer (bigint) as its parameter n, and it will compute the factorial n! of the value and return it as its result (as a bigint). Write this functions using a loop (do not use recursion). 2. Write the factorial function again, but using recursion. Call this function factorialRecursive(). The function takes the same parameters and returns the same result as described in...
Hi please help me with this zybooks question asap. Thanks 4.17 Chapter 4 Program: Sum of Numbers/C++ program Write a C ++ program that asks the user for a positive integer value by prompting "Enter a positive integer number: ", read in that number, then use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2,3, 4…50....
**IN C***
*
In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...
INTEL 80x86 ASSEMBLY LANGUAGE CODE Write a windows32 assembly language program that utilizes a recursive procedure. The main (_MainProc) procedure should: accept, from the user, a positive integer. Guard against non-positive integers being entered using a loop. call the sumseries sub-procedure using the cdecl protocol, receive the results of the sub-procedure, and display the results. The sumseries sub-procedure should: recursively find the sum of the series: 1*2 + 2*3 + 3*4 + ... + i*(i+1) (This is an iterative definition....
In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....
Please solve this question using c++ language
Problem 2. More Probleml. The program builds the array of integers that contains duplicates as well. Your program should find the sum of all unique elements in the array using a function findUniqueSum Arrays Write a program that as before asks the user to enter input as in оn Sample Input/Output Enter a list of numbers ending with -999 3 1 4 55-999 The sum of unique numbers is: 13 Enter a list...
Programming Language: Java Please write a program that uses a recursive algorithm to compute the determinant of a matrix. It should read the order of the matrix, read the matrix, print it out, compute, and print the determinant. Your program should be able to evaluate multiple matrices on a single execution. For class purposes, your program should handle matrices up to and including those of order 6. You are required to use an array for this problem. Your solution must...
Please help me with this program.You are to write a C++ program that will read in up to 15 students with student information and grades. Your program will compute an average and print out certain reports. Format: The information for each student is on separate lines of input. The first data will be the student�s ID number, next line is the students name, next the students classification, and the last line are the 10 grades where the last grade is...