C++ :: Finding Maximum Of A Function

May 8, 2014

What is the syntax to find the maximum of a function over the interval a≤x≤b starting at a with a step size of Δx ?

View 1 Replies


ADVERTISEMENT

C++ :: Finding Maximum Value In A Map

Jul 26, 2014

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?

View 1 Replies View Related

C++ :: Finding Maximum Value In A Vector

Nov 12, 2014

This is part of my main code that is giving me compiler issues.

//Find max value
max = max_element(vecTemperature.begin(), vecTemperature.end());

I keep getting an error saying "[Error] cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to 'int' in assignment"

View 2 Replies View Related

C :: Finding About Maximum / Minimum Point

Oct 29, 2014

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.

View 4 Replies View Related

C++ :: Finding Maximum And Minimum Values Of 10 Numbers Using For Loop

Jan 22, 2013

I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!

#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;

[Code] ....

View 2 Replies View Related

C/C++ :: Unable To Send Maximum Long Value Through Function Call

Jun 11, 2014

I am trying to send the maximum long value through function call, but i didn't print proper value..

[
#include <stdio.h>
long long floatToInteger_old(float value){
printf("float val : %e",value);
}
int main(){
float value = 340168346567;
long long finalhexVal = floatToInteger_old(value);
return 0;}
]

my actual output is 340168346567, but it is printing 3.401683e+011 or 340168343552.000000.
how can print exact value what i am sending.

View 7 Replies View Related

C++ :: Write A Function That Return Maximum Value Of Array Of Doubles?

Oct 9, 2014

I'm trying to get correct answers from my exam to study for a midterm:

Write a function that returns the maximum value of an array of doubles.

Declaration:

double maximum(array[],int a_size);

So far I've done:

double maximum(array[], int a_size) {
double maxVal;
maxVal = array[0];
for(int i=1; i < size; i++) {
if(array[i] > max
maxVal=array[i]
}
return maxVal;
}

I just need any corrections.

Second, I need to write a function definition that merges two vectors containing integers, alternating elements from both vectors.

Prototype:

vector<int> merge(const vector<int> a, const vector<int> b);

This is my definition so far:

vector<int>merge(const vector<int> a, const vector<int> b){
vector<int> merged;
for(int i=0; i<a.size+b.size; i++) {
if(flag == true)
merged.push_back(a);
flag = false;
else
merged.push_back(b)
flag = true;}

I think I'm lost in the second part...

View 2 Replies View Related

C/C++ :: Finding The Value Of Sin(x) Without Using Math Function

Apr 14, 2013

How can i solve a problem of sin(x) without using any math.h and only using my own declared function.

#include <stdio.h>
int fact (int a) {
    int i;
    int k = 1;
    for (i=1;i<=a;i++)

[Code] ....

View 3 Replies View Related

C++ :: Function Not Finding Largest Integer?

Feb 10, 2013

My code compiles fine but it doesn't seem to want to calculate the max integer. It calculates min and average fine but I'm not seeing what is wrong with my code. The max integer keeps coming out wrong.

#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cstdlib>
#include <algorithm>
using std::swap;

[Code] ....

View 1 Replies View Related

C :: Finding Error In Delete Node Function

Sep 12, 2013

I have written a delete node function to delete a node in a linked list by the index number. Here is the code:

Code:

void delete_node(struct node **start,int index_no)
{ int counter=0;
struct node *current=*start, *prev=NULL;//Current holds start and prev holds previous node of current
while(current->next!=NULL)

[Code]....

note that I know if the head node turns out to be the indexed position, there is no way to delete that node in the current coding. But please after correcting the present node add that part of the code separately.

View 5 Replies View Related

C++ :: Finding Size Of Array In Called Function

Nov 27, 2013

How to find the size of an array in called function? When we pass the array a argument to function definition we will be having base address of array, so my understanding is that we will not get the size of an array? but is there any hacking for this to find size of array other than passing as size an argument to this called function?

View 3 Replies View Related

C++ :: Finding Sum Of Two Fractions - Return Array In Function?

Jul 30, 2013

I am making a function that finds the sum of two fractions(fractions are arrays of 2 elements). how would I return an array?

int addFrac(int f1[2], int f2[2]){
int num1 = f1[0]; // numerator of fraction 1
int den1 = f1[1]; // denominator of fractions 1

[Code] ......

View 2 Replies View Related

C++ :: Finding Function Documentation For Header File

Nov 23, 2013

I would like to see what functions the following header file has:

#include <tf/LinearMath/Transform.h>

Any website that has all the c++ libraries and where to find the functions that come with this?

View 4 Replies View Related

C :: Recursive Function For Finding And Summing Prime Factors?

Mar 6, 2015

main function:

Code:
int main(){
int n, s = 0;
printf("Insert number: "); scanf("%d", &n);
if (n == 0 || n==-1 || n==1){ printf("No prime factors!
"); return 0; }
if (n < -1) { n = - n; printf("Prime factors: -"); }

[Code] ....

Recursive function

Code:
static int i = 2;
int primefactors (int n) {
if (n == 1) return 0;
if (n%i == 0) {
printf("%d ", i);
return i + primefactors(n / i);

[Code] ....

View 8 Replies View Related

C :: Function Macro For Finding Square Root Of A Number

Jul 13, 2014

How to write a function macro in C for finding the sqrt of a number?

View 2 Replies View Related

C :: How To Print Only Maximum Value

Sep 20, 2013

I have this code that determines the amount of people that can fit on some trains in different train combination scenarios. Here is the code:

#include<stdio.h>
#include<stdlib.h>
int main(void) {
int total_track, max_train_length, num_people, num_trains, tl;

printf("What is the total length of track, in feet?

[Code] ....

I need to now "pick the winner," or the highest value for num_people computed. How would I go about this and why?

View 6 Replies View Related

C :: Is There A Maximum Capacity For Stdin

May 23, 2013

Is there a maximum capacity for stdin ?

View 2 Replies View Related

C :: Find The Maximum Subsequence Sum

Mar 12, 2014

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?

View 8 Replies View Related

C :: Minimum And Maximum In All Positions

Jan 4, 2015

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

[code]....

View 6 Replies View Related

C :: How To Find Maximum Value Of Array

Oct 29, 2014

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.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code].....

View 10 Replies View Related

C++ :: Identifier Not Found For Maximum Value

Sep 10, 2013

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;

[Code] .....

View 5 Replies View Related

C++ :: Maximum Size Of Vectors

Dec 9, 2013

I have a vector of vectors declared as:

vector<vector<int>> v;

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?

View 6 Replies View Related

C++ :: Vector Reaching Its Maximum Size

Feb 5, 2014

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#

View 3 Replies View Related

C/C++ :: Maximum Divisor Sum - Determinate Number Between 2 And N

Oct 17, 2014

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 ?

View 4 Replies View Related

C/C++ :: Find Maximum Of Three Numbers Given By User?

Jan 25, 2014

I'm new to C++ and I'm trying to solve the question but there is just something wrong somewhere.

#include <iostream>  
using namespace std;  
int main() {
    int largest;
    int a;
    int b;
    int c;  
    cout<< "Enter first value";

[Code] ....

View 1 Replies View Related

Visual C++ :: Get Maximum Memory Usage Of App?

Apr 21, 2013

I use Visual C++ to write a native C++ application. How to know the maximum memory it will use during its execution?

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved