I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.
Code:
private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];
[Code] .....
I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this
Code:
int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)
[Code] .....
It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually?
Here's the code that returns maximum sum of a subsequence from a given array. This is according to "Programming Pearls" by Jon Bentley. I have come up with an example for which this program won't work. And here's that example:
{ -10, 11, 10, -10, 2, 3, -6, 1 }
Max subsequence sum above is 21. 2nd and 3rd elements.
But the program returns 16. It sums 2nd through 6th elements and returns. Why would the writer explain something with such depth, only to give a program that doesn't work in all instances?
int MaxSum(int lo, int hi, int* arr) { if (lo > hi) { return 0; } if (lo == hi)
Any way to determine the highest value of an array I created with random numbers. I am confused because the array needs to be initialized in the main, but populated in a function. I was able to populate it using a pointer variable and my results came out good for the initial array values and elements.
In order to figure out the max, I think I would need the results of the populated array. How do I do this when the populated array is stored in a pointer variable? Would I need to create a pointer to the first pointer I created? I tried creating another pointer to the initial array and printing that, but my results were not good.
I was given some practice problems in my programming class, to prepare for the final and I don't quite understand what this one is asking for exactly:
Write the remainder of the program to find the maximum value for the middle row of the array data. Print the max after finding it. Your code should work for any 2D array of ints with three rows and four columns, so don't hard-code your program to these specific values.
The first loop will print out all of numbers in the velocity column. The second while loop is looking for the maximum value in that column. It is supposed to print out the max velocity in the end of the second loop. However, when I build and run the program, it's crashed. I run debugger and received "Segmentation fault" error. When I eliminate the second loop, it run just fine I use Code::Block for text editor.
I have an array of "2,3,4,5,6,9,10,11,12,99". I need to create a table of this which i have done using case
1. Find the maximum value of the array 2. Find the sum of the first and last element of the array 3. Swap the adjacent pairs of arrays 4. Display the values in array 5. Quit
Please enter choice:
but when i try running the program i did i keep having the break or continue pop up ....
#include <iostream> using namespace std; int main() { int choice; int number[10] = {2,3,4,5,6,9,10,11,12,99};
So I need to write a function that has 2 arguments that are strings. It returns 1 if the first string is a subsequence of the second string, and 0 otherwise.
For example, given 2 strings like "foobar" and "obr", the function should returns 1 whereas "foobar" and "obo" returns 0.I have tried writing the code myself,
Code: int sub(char *s, char *t) { int i; char *p; for (i=0; t[i] != ''; i++) { p=strchr(s,t[i]); if (p==NULL) return 0; else strcpy(s,p); } return 1; }
So my strategy is as follows: 1. Find the first letter of the second string in the first string (foobar). 2. If there's a match then continue to search for the second letter of the second string starting from the index of the first letter plus 1. (obar). Otherwise return 0,.........
However the function always return 1 no matter what the input strings are.
In the implementation of a program to find the length of the longest common subsequence, what does line 14 do?
void lcs( char *X, char *Y, int m, int n ) { int L[m+1][n+1]; /* Following steps build L[m+1][n+1] in bottom up fashion. Note that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */ for (int i=0; i<=m; i++)
I found this implementation on a website for printing the longest common subsequence. But it gives wrong answers for some reason even though the code seems right to me.
Here is the code:
#include <iostream> int lcs(char *X, char *Y, int m, int n) { int L[m+1][n+1]; for(int i = 0; i<=m; i++)
Suppose that a map is defined thus: map<sttring, int> mymap;
I wanna find k maximum values. Is there a way to find the maximum value in an efficient manner? Or else, How can I sort them and then find the k first elements?
I wrote a program to find the minimum and the maximum values from a vector. It works fine. What I'm trying to do is show the positions of said values and it's not working quite right. When I insert 4 elements: 2 0 1 3 it says:
"The min and max are 0 and 3 The position of the min is: 01 The position of the max is: 03"
What am I doing wrong? Here is the code:
Code:
#include <stdio.h> #include <conio.h> int main() { int A[10], i, j, n, min, max, C[10], k=0, D[10], l=0; printf("Insert no. of elements in vector A
I am working on a couple C++ projectsfor my class. On one of my projects I get this error "identifier not found" for maximumValue. here is the code that I have done. I have got almost all the code from my text book..
// Three numbers.cpp : Defines the entry point for the console application.//
#include "stdafx.h" #include <iostream> using namespace std; int main() { // demonstrate maximum int value int int1, int2, int3;
My program works fine with a small number of insertions to v. However, with a huge number of insertions my program stops working without telling me the reason... I guess that vectors might not grow after a certain size (im not sure)
1. What is the maximum size that a vector of vectors can grow? 2. I'm using Microsoft visual studio 2012, Is their anything I can do with the settings to increase the size of my vector? something beyond 1000000 rows?
A function finds approximate maximum or minimum point of a second degree polynomial function (the point where the derivation will equal to zero ). The input polynomial function will be in the following format:
x2 + bx + c = 0 .
Your C function should take a , b and c as input parameters. Your C function also should take the srch_starting_point and stp_sze from the user. Finally, print the resulting maximum or minimum point (m_x, m_y) and step count (n_step) in your function.
For example, if the input is (a, b, c, srch_starting_point, stp_sze ); 1 1 1 -3 1
Output similar to; Maximum point results ( m_x, m_y, n_step ) -1 1 2
i can find the minimum point at first(Using derivation). After choosing starting point, staating point gets lower step size by step size. I can compare numbers to the minimum number. Afterwards, to find m_y i put m_x in the function. Finally, I put a counter to count steps.
My program enters the size of the vector from the user and then creates a vector of vectors (lets say SIZE1). In addition the user enters the number of vector of vectors he needs (lets say SIZE2) as follows:
class Vectors { // member functions goes here private vector<vector<int>> vectors; vector<int>::iterator it;
[Code] .....
With a few calculations and insertions to my vector (vector of vectors)... the program works fine and gives me the results...
However, with huge calculations and insertions the program stops working and gives me this message
"Unhandled exception at at 0x770DC41F in Test.exe: Microsoft C++ exception:std:bad_alloc at memory location 0x001CEADC"
Thus, it seems that the vector reached it's maximum size... I tried to use reserve() but did not work
I read that "By default, when you run a 64-bit managed application on a 64-bit Windows operating system, you can create an object of no more than 2 gigabytes (GB). However, in the .NET Framework 4.5, you can increase this limit"
What do you think would be the best option for me to do (note my program is very long and complex)(I'm currently using Microsoft Visual Studio 2012 32Win application):
1. convert my program to the .NET Framework (C++)
2. convert my program to C# in case c#
3. do any settings on my computer (my workstation has a 3.6GHZ xion processor with 32RAM
4. convert to another version of C++ that does not have any restriction on the size of the array (if available)
Please note that I never worked neither with the .NET framework nor C#
The problem says that i have a number n > 0 and the program should determinate the number between 2 and N who has the maximum divisor sum (1 and N wont count as divisor). If i have more numbers with maximum divisor sum, should wrote only first number. Exemple: for N = 100 , will show 96 bcoz he has the maximum divisor sum, which is 155. For the start i tried to show only the maximum divisor sum, not the number who has the maximum divisor sum with this code:
#include<stdio.h> int main() { int n,s=0,i,m; printf("Please introduce the number N > 0:"); scanf("%d", &n); i = 2;
[Code] .....
And it shows me 116, but the correct results is 155. Which is the problem ?