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


ADVERTISEMENT

C++ ::  Selecting Arrays With Maximum Number Of Elements

Sep 10, 2013

Supposing you have a 3 or more overlapping arrays (arrays having elements in common), and you wish to select 2 or more of the arrays with the maximum number of elements but less overlap as compared to the rest of the overlapping arrays.

Eg. A[4],B[6],C[5]. A+B contains 10 elements but say the overlapping element is 3, meaning it has 7 unique element.

Also B+C=11 elements , but supposing it has 5 overlaps, it would mean it has only 6 unique elements. A+B+C=15. Supposing the overlaps are 11 then it means the unique elements are 4. Ect. So per the example, the best array options with most unique element would be A+B .

View 4 Replies View Related

C++ :: Return Maximum Frequency Number From Stack

Dec 17, 2013

I designed one mfc vc++application in which data received from udp is stored in file as well as in stack.I used stl for stack; it stored elements as per receiving order,but i want to return repetitive number from stack,how to use stack as function parameter & retrieve elements of stack as an array? I write code for push elements in stack given below.

<template< typename T > void pushElements( T &stackRef,int value) {
stackRef.push( value);
}/>

View 1 Replies View Related

C# :: Determinate Type Of Object And Pass It Through Method

Sep 18, 2014

I got base class called Statistic and inherited classes from it : lsp, cpu, memory. Those methods inheriting some of methods from Statistic and implement also theirself methods. I prepared some new class called ExecuteRequest which is taking Statistic object in the constructor. What i want to achieve is after i put e.g LSP to this class i would like to determinate what specific object it is in this case LSP right? Then having that i would like to put this object to RunRequest method. How can i achieve that? See my code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SOAP_testing {
public class ExecuteRequest

[Code] .....

View 14 Replies View Related

C/C++ :: Program To Read Sequence Of N Integers And Print Number With Maximum Occurrence

Mar 24, 2014

write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.

View 1 Replies View Related

C++ :: Calculating Greatest Common Divisor?

Jan 12, 2013

I have written the following function to calculate GCD of floating point numbers, but when I run this for (111.6, 46.5), the calculation of fmod(a,b) in the funciton starts giving the wrong result after 2 recursive calls. I am unable to find the error here.

float gcd(float a, float b){
if (a>b) {
if(b==0){

[Code]....

View 1 Replies View Related

C++ :: Finding Greatest Common Divisor?

Jan 2, 2015

Is there a function or algorithm in stl in c++ the gcd of a vector ?

View 1 Replies View Related

C++ :: Greatest Common Divisor Of Two Numbers

Nov 19, 2014

How do I get the greatest common divisor of two numbers in C++?

View 1 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++ :: 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 :: 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++ :: 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 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 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++ :: 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++ :: 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

C :: How To Find Maximum Value For Middle Row Of Array Data

Aug 2, 2014

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.

Code:

#include <stdio.h>
int main(void)
{
int data[][4] = {{ 5, 8, 7, 2},
{ 3, 10, 1, 9},
{ 6, 12, 5, 0}};

View 8 Replies View Related

C :: Find The Maximum Value In A Column Of Text File

Jul 28, 2014

I have problem with finding the maximum value in a column. This is my code

Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
fp = fopen ("C:
ocket1.txt", "r");
float time, altitude, velocity, acceleration, amax, bmax;

[Code] ....

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.

View 8 Replies View Related

C :: Display Average / Maximum And Minimum Mark

Sep 29, 2013

Program that reads 10 students marks and display the average, the maximum and the minimum marks.

Code] ....

#include <Stdio.h>
main(){
// Local Declarations
int marks[10];
int i; /*loop counter */
int avg;
int sum = 0;

[Code] ....

In this program i am able to get Average Marks and Minimum Marks But i am not able to get the Maximum Marks Output correct.

View 6 Replies View Related

C++ :: Display Maximum Value In Two Dimensional Array Of Integers

Feb 3, 2014

How will you code a program that displays the maximum value in a two dimensional array of integers. the program will ask the user to input the 4x5 array?

i know how to code it. but i dont know what to do to find the maximum value. :( how to find the maximum?

View 4 Replies View Related







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