Tag: Cpp

Matlab Simple mex Example

Matlab mex functions can be used to extend Matlab functionality or to improve performance by using compiled code as opposed to interpreted matlab syntax. Using mex functions is explained in many places on the web however the following is a simple template example to demonstrate that: //This is required #include "mex.h" //Gateway function to specify

Copy String C++

Problem Write a C++ function to copy an existing string. Do not use built in functions. Solution This is a straight forward question and to my surprise I was asked this question in a site interview. If you are not prepared you might stumble on the easy ones. The idea is to allocate memory for

Recursive Upper Function

Problem Write a C++ recursive function to convert a character string into capital letters. Solution Instead of looping in the string character by character we can recursively call a function while advancing an index each time. Once the index reaches the end of the string we stop recursion. Converting a letter into capital case in

Recursive Multiplication C++

Problem Write a recursive function to compute the product of two positive integers. Solution The product of two positive integers (A*B) is nothing but the sum of the first integer (A), (B) times Code Here is the code in C++ //Includes #include <iostream> //STD using namespace std; float RecursiveProduct(int a, int b) { //Base case

Recursive Average

Problem Write a recursive algorithm to compute the average of an array of numbers. Solution The average of an array of numbers is the sum of all numbers divided by the total number of elements. It is the same as dividing each number by the total number of elements then adding each division result to