C/C++ :: Find Largest Sum Down A Triangle - Code Error With Recursive Function
Sep 29, 2013
Thing I want is find the largest sum down a triangle,(moving to adjacent numbers on the row below )there are many methods to go down.
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
I wrote a program with a recursive() called finder. But it dose not work properly,at run time it becomes to a infinite status. How to detect the error at runtime. Here is the code.
#include<stdio.h>
void finder(int x,int y);
int tot;
[Code] ....
I think the error is the changing value of x after a round of for loop.
View 2 Replies
ADVERTISEMENT
Apr 6, 2015
How to find triangle in an array of n triangles which has the largest area?
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
typedef struct {
double x,y;
[Code] .....
View 14 Replies
View Related
Apr 8, 2014
Is there any way to programatically find if the given code is taking recursive approach or iterative apporaoch using concept of files in C programming.
View 3 Replies
View Related
May 13, 2014
im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];
[Code]...
View 5 Replies
View Related
Jul 31, 2014
My while loop is the problem. I want to use a non-recursive function to make the triangle number the sum of all whole numbers from 1 to N.
#include "stdafx.h"
#include <iostream>
using namespace std;
int triangle(int t);
[Code] ....
View 2 Replies
View Related
Jan 30, 2013
find inserted numbers, let say 10 numbers and find the largest and second largest number with their position in an array?
View 3 Replies
View Related
Apr 28, 2014
Write a program that uses two functions; one finds the largest number and second largest number; and second function finds the average. The data, comprising of 20 different temperature values, is available on a file.
View 1 Replies
View Related
Mar 6, 2015
I am trying to create a function to find the entry point of my map.But my program does not seem to be working correctly. I am trying to place a dot there because I will have to use recursion to fill up the whole map. But I'm not asking for the answer. I just need writing a function to locate the starting row for the first column of the maze (first non zero element). My code seems to have a bug in it when I try and call my function FindEntry. What I am trying to do is read in column by column until I can find the starting point and then place a dot there with ASCII character 249. This is my code so far:
Code:
#include<stdio.h>
#include<Windows.h>
#define HEIGHT 21
#define WIDTH 78
[Code]....
If you try and run it, it will give you a bug. But if you comment out the FindEntry function in the main it will work and look like this:
View 7 Replies
View Related
May 18, 2013
I am supposed to write a recursive function which find the partition of a number n ,, for example if n=3 , it should print 1 1 1 , 1 2 , 3
I wrote the program but i am getting the two partition 1 2 and 2 1 which are the same ,, how can i avoid that ?
this is the code :
void PrintPartition( int n , int A[] , int j ) {
if( n<=0 ) {
printArray( A, j );
return ;
} for( int i=1 ; i<=n ; i++ ) {
A[j]=i;
PrintPartition( n-i , A ,j+1 );
} }
the first call of the function is : PrintPartition( n , A , 0 ) ;
View 3 Replies
View Related
Feb 21, 2015
For an assignment I have to finish prewritten code which consists of multiple source files and a header file.
Code:
#include "tree.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
[Code] .....
I understand that I have to find the height by using _left->height() and _right->height() as long as it is not a null-pointer , each time I do this the values of _left and _right change. That way you can check if it is possible to go further down in the tree. I also have to use a counter to keep track of the number of layers at each side of the root. I don't understand how to implement it.
View 3 Replies
View Related
Jul 26, 2013
Its a code to find the largest number of a 3X3 matrix.The logic seems to be right........
Code:
#include<stdio.h>
main() {
int matrix[3][3],i,k,j,*a;
a=&matrix[0][0];
printf("Enter the elements");
for(i=0;i<=2;i++) {
[Code]....
View 7 Replies
View Related
Oct 18, 2014
Write a program that will find the smallest, largest and average of the values in a collection of N positive integer numbers.
View 12 Replies
View Related
Apr 19, 2013
I have a std::map<int, foo>
what's the ideal way to get an iterator to the item that has the largest key (int) smaller than a given value.
basically, the item before upper_bound(). I can use upper_bound() and then decrement, but it needs special cases for both end() and begin(), and in the case of end() I'm not sure how I get it to the last item in the map, afaik, we're not allowed to decrement end().
Code:
auto it = mymap.upper_bound(x);
if (it==mymap.begin()) // first item in the map is already too large. reject
NotFound();
else if (it==mymap.end())
[Code] .....
// here it points to largest item smaller than x.
I can iterate over the entire map and do a compare, but then I pretty much loose the benefit of the binary search.
View 2 Replies
View Related
May 26, 2013
i have written a program to find area of triangle, but i meet some errors,
//******area of triangle******//
#include<iostream>
using namespace std;
[Code].....
View 1 Replies
View Related
Oct 4, 2013
I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.
input file text (first number is num of auctions, after that it's num of bids, then the bids):
5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23
Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!
The silent auction raised $2470.00 for charity!
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
[Code].....
View 4 Replies
View Related
Aug 30, 2013
While finding the primes , I do not know how to make it into one array so that...
View 7 Replies
View Related
Mar 6, 2015
How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.
I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int maxNum=0, minNum=0, value, count=0, sum=0;
double average;
[Code] ....
View 4 Replies
View Related
Feb 27, 2013
I made the code that stores and prints 5 row by 5 column values but how to find the largest number from them.What should I do to find the largest number?If I use if-else then it would be very tedious but I think there is way out with for loop but still I can't frame the logic. Here is the code
Code:
#include<stdio.h>
main() {
int lnum[5][5];
int i,j;
for(i=0;i<=4;i++) {
[Code] .....
View 7 Replies
View Related
May 30, 2014
I seem to have reached a dead end in a program I am attempting to write.The purpose of the program is find the smallest, largest, and average values in a collection of N numbers. It needs to get the value of N before scanning each value in the collection of N numbers.I'm having trouble creating comparisons for each set. I have a feeling because of the way I structured my program, I'm unable to make a proper comparison. Maybe my approach was wrong as soon as I got to the for statement to loop N sets and N numbers.Here is my code so far:
Code:
#include <stdio.h>
int main (void)
{
int num_sets, num_of_integers;
int count, count2, set, sum = 0;
int num, avg;
}
[code]....
/* Here is where I would continue to attempt to make a comparison between sets to determine smallest to largest */
return 0;
View 5 Replies
View Related
Nov 16, 2013
I am writing this code, and I every time I run question A, no matter what numbers I put in, I get "larger = 0.
#include <iostream>
using namespace std;
int awesome ();
int best ();
int crazy ();
int main () {
char letter;
int smallestNumber;
int largestNumber;
[Code] .....
View 2 Replies
View Related
Mar 6, 2015
In this code nothing modify except function minMaxSearchRecursive
Code:
int min(int a, int b) {
if (a < b) {
return a;
} else {
return b;
[Code] .......
View 9 Replies
View Related
Mar 27, 2015
I have a function in one src file called from code in a different src file.
In ig_cfunc.cpp
Code:
#include "ig_tools.h"
int x2_count = 0.0;
float rel_branch_degree_tmp = 0.0;
string type;
vector<int> is_disp_type;
[Code] ....
I am getting a linker error,
Code:
ig_cfunc.cpp:1609: error: `calc_rel_branch_degree' undeclared (first use this function)
I have deleted all of the objects and recompiled to make sure that everything is in sync. I can't see what the issue is here and I'm not sure what to do next. This code actually worked until I changed the name of the function, so the types are all correct and such. This is the format I use for all external functions ....
View 1 Replies
View Related
Sep 8, 2014
Cannot manage to find the error source when i try running the program, the first part of the program runs just fine its when i try to get the temperature one that i get the error
#include <iostream>
#define pi 3.141592
using namespace std;
int main() {
double r, h; //declare variables for radious and height
double Surfacearea;
[code]....
View 1 Replies
View Related
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
Mar 25, 2015
In this assignment, you are required to write a function called largest square. Your function should take a 2 dimensional array, 2 integers which represent the number of rows and columns in the array, and prints out a 2 X 2 array which represents the largest square in the array. The largest square means the square for which the sum of its elements is the greatest in the array. Submit your function in a file called largestSquare.c
Example: Given the array 1 2 3 4
5 6 7 8
9 10 11 12 the output should be 7 8
11 12
Example 2: Given the array 8 2 6
3 7 3
6 1 1 the output should be 8 2
3 7
The prototype of your function is void largestSquare(int[rows][columns], int rows, int columns).
Am I anywhere close with what I've started?
//
// main.c
// largestsquare
//
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
int rows, columns;
[Code] ...
View 5 Replies
View Related
Sep 1, 2013
//Point.cpp
#include "Point.h"
#include <iostream>
#include <cmath>
using namespace std;
Point::Point() { //Initialise the point to the origin.
[Code] ....
void Triangle::print() { //print out the Triangle with the format "( (x1, y1), (x2, y2), (x3, y3) )"
How do I accomplish this? When i test with cout << _point1.print(), there's an error:
[Error] no match for 'operator<<' in 'std::cout << ((Triangle*)this)->Triangle::_point1.Point::print()'
View 4 Replies
View Related