Categories

## Stack Overflow for Fractional Knapsack

I am fairly new to C++. I have implemented the fractional knapsack problem in c++ for the course “Algorithmic Toolbox” on Coursera: #include <iostream> #include <iomanip> using namespace std; int get_max_index(double A[], double B[],int l) { /* int A = array of value int B = array of weights int l = length of the […]

Categories

## 2D matrix vector multiplication using mpi in C

I’m new to parallel programming, and my project is the two-dimensional matrix vector multiplication using mpi in C programming language. I have this multiplication function, but I don’t know exactly how to run it with mpi. Can you help me, please? I write these commands, \$ mpicc -g -Wall -o matrix2d matrix2d.c -lm -c \$ […]

Categories

## Comparing double in C++, peer review

I have always had the problem of comparing double values for equality. There are functions around like some fuzzy_compare(double a, double b), but I often enough did not manage to find them in time. So I thought on building a wrapper class for double just for the comparison operator: typedef union { uint64_t i; double […]

Categories

## how to create loop to go though the array

#include <stdio.h> #include <iostream> #include <conio.h> #include <locale> using namespace std; class Equation { private: double a, b, c, d; public: double fun; Equation() {} Equation(double a, double b, double c, double d) { fun = a; fun = b; fun = c; fun = d; } }; int main(int argc, char** argv) { for […]

Categories

## C intro – How to pass a parameter by reference in function?

I’m working on my intro C course assignment and I’m tasked with the following… Write code for a function that receives two parameters (a,and b) by value and has two more parameters (c and d) by reference. All parameters are double. From main, use scanf to get two numbers, then call the function, and then […]

Categories

## Can’t compile with gcc-7

I am trying to compile some code with GCC-7 on MacOS Catalina. The GCC-7 was installed using homebrew brew install gcc@7 The code is the following: #include <stdlib.h> #include <math.h> double distance(double *a, double *b, int d) { double dist = 0; for(int i = 0; i < d; i++) { dist += pow(a[i]-b[i],2); } […]

Categories

I am writing a program in my AP java class and I am very confused. The program is supposed to read a data file using another program called EasyReader. The program consists of an Object class that finds the largest number, medium number, and smallest number. The Test class is supposed to read the data […]

Categories

## SUMMA matrix multiplication

I am trying to implement summa algorithm for matrix multiplication. I am using mpi library to implement it. My code looks like following: #include <stdio.h> #include <time.h> #include <stdlib.h> #include <math.h> #include “mpi.h” #include <string.h> #define min(a, b) ((a < b) ? a : b) #define SZ 4000 //Each matrix of entire A, B, and […]

Categories

## How to translate this Javascript snippet to C# [on hold]

Javascript: function bounds(a, b, c) { null != b && (a = Math.max(a, b)); null != c && (a = Math.min(a, c)); return a } Honestly, I don’t even understand what is going on here. If b isn’t null, then a gets set Math.max(a, b). if c isn’t null, a gets set from Math.min(a, c)? […]