C++ :: Sum Of The Biggest Numbers In A Triangle

Jan 3, 2014

After trying to understand the problem i finally gave up. The problem requires me to calculate the sum of the biggest numbers in a triangle.

For example: 5
4 0
3 8 2
2 7 9 6

Here is the solved problem from the book(It uses recursion, but i do not get it at all)

#include <iostream>
#include <fstream>
using namespace std;
int triunghi[50][50], n, sum=0;
int suma_max(int i, int j);

[Code] .....

I doesn't give me the same result(26) if a change the order of the numbers in the triangle.

View 3 Replies


ADVERTISEMENT

C++ :: While Loop - Use Non-recursive Function To Make Triangle Number Sum Of All Whole Numbers From 1 To N

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

C/C++ :: Find Biggest Number In A Row

Apr 11, 2015

I'm having this issue where my else if statements are not working. My program only works correctly when I go into my if statement and change the first part of my array to the specific row I am trying to find ex [0][i] to [1][i].

int getMonthMax(int scores[][COLS],int month){
int highestN=0,i, j;
for (i=0;i<ROWS-1;i++){
if(scores[0][i]>highestN){
highestN=scores[0][i];

[Code] .....

View 4 Replies View Related

C :: Finding The Biggest Number In Array?

Feb 2, 2014

I'm supposed to find the biggest number (largest value), in any given array A with n numbers. (no floats)

My thoughts here are, check if A[0] > A[1]. if yes, check if A[0] > A[2]. If no, check if A[1] > A[2] etc.

I'm not sure how I can do this in code. I'm thinking if A[0] > A[1] is true, then set A[0] = A[k]. Kind of set it aside, and use that for the next if test. But I'm not sure how to do it.

This is my code so far.

Code:
int main(){
int A[7] = {12, 6, 9, 33, 2, 25, 53};
int i, k;
k = 0;

[Code]....

I'm aware of the flaws here, but this is the best I can do so far. How can I get the if test to use A[k] next, as A[k] will always be the biggest value?

View 11 Replies View Related

C :: How To Find Biggest Column Of Matrix

Jan 23, 2013

Here is the draft of code that i designed. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

View 14 Replies View Related

C :: How To Find Biggest Prime Factor Of A Number

Feb 10, 2015

i want to write a program which find the biggest prime factor of a number for example the biggest prime factor of six is three or the biggest prime factor of fifteen is five. What is my program bug

Code:

#include <stdio.h> // main functions
#include <math.h> // for sqrt function
int main()
{
int i, j, k, f; // F = Flag;
printf("Enter K

[Code]...

View 9 Replies View Related

C++ :: Implementation Of Function In BST To Return Parent With Biggest Son / Sons

May 30, 2013

I got a code of a BST and i need to create a function that will return the value of the parent that it's son/sons sum to the biggest sum - BST and not AVL.

I assume that the shortest code will be recursive but i didn't manage to get it right - i'll send the code without my function because it's wrong - l

#include <vector>
#include <iostream>
using namespace std;
//-----------------------------------------------------------------
// class Node
// a single Node from a binary tree
//-----------------------------------------------------------------
template <class T> class Node

[Code] ....

View 1 Replies View Related

C++ :: Find Biggest Part Of Column Over Diagonal Of Matrix

Jan 23, 2013

How to find the biggest column of the matrix (higher of main diagonal) Here is the draft of code that i desighned/ Of cause it has a several mistake. My task is here to create the matrix, allocate the dynamic memory for it, and to find the biggest sum of the column elements that is located over main diagonal. So main points is correct memory allocation, and the sorting to the biggest sum of column higher than diagonal.

#include<iostream>
#include<conio.h>
#include<time.h>
using namespace std;

[Code]....

View 5 Replies View Related

C++ :: Printing A Triangle

Oct 7, 2013

What the heck is wrong with my logic? I just print a rectangle!!! I have played with thing for ever it seems. I thought the rotating part would be hard but now I find myself stuck.

Code:
#include <istream>
#include "triangle.h"
using namespace std;
void triangle::create_triangle() {

[Code] ....

View 13 Replies View Related

C++ :: Right Triangle Program Using X And Y

Jan 12, 2015

I originally had the user input three different lengths and then used this to determine whether or not it was a right triangle.

if(c==sqrt(a*a+b*b)||a==sqrt(b*b+c*c)||b=sqrt(a*a+b*b))

Now it has to be modified in order to accept the input 2,2 4,4 and 6,8(only an example) and be able to find out if it is a right triangle. I was told that arrays were not necessarily the only way to go about it.

View 1 Replies View Related

C :: Finding Out Neighbors Of Triangle

Mar 2, 2015

I need to find out neighbors of a triangle and loop it over entire unstructured grid. How to do it?. Cell numbers are random so I am unable to loop over all cells.

View 9 Replies View Related

C++ :: How To Compute Perimeter Of A Triangle

Jun 26, 2013

I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.

#include <iostream>
#include <cmath>
using namespace std;

struct Point{
double x;
double y;

[Code] ......

I expect to get 0 for triangle1, but I get some strange value...

Here is the result

Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843

View 2 Replies View Related

C++ :: Inverted Difference Triangle

Jun 21, 2013

Similar to Pascal’s triangle, the difference triangle has some interesting properties that find applications in various fields of the natural and applied sciences. In simple terms, a difference triangle is a set of integers arranged in an inverted triangle where each inverted triangle triad has its lower element equal to the difference (absolute value) of the two elements in the upper row. A difference triangle can be created from a sequence of integers forming the uppermost row by iteratively taking differences between consecutive terms to form the next row until a single-element row is created.

Example Consider the sequence 5, 8, 13, 21, 34, 55 from the Fibonacci series as the uppermost row of the difference triangle. The difference between successive elements form a new set: 3 (= 8 – 5), 5 (= 13 – 8), 8 (= 21 – 13), 13 (= 34 – 21), and 21 (= 55 – 34). The process can then be repeated until there is only one element left giving the following difference triangle:

5 8 13 21 34 55
3 5 8 13 21
2 3 5 8
1 2 3
1 1
0

Problem Write a program that forms a difference triangle using a given series of numbers as topmost row.

View 2 Replies View Related

C++ :: Model A Triangle With Three Vertices

Dec 27, 2013

Write a class called MyTriangle, which models a triangle with 3 vertices, is designed as follows. It contains:

1. The MyTriangle class uses three MyPoint instances as the three vertices.

2. Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.

3. A constructor that constructs a MyTriangle with three points v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).

4. An overloaded constructor that constructs MyTriangle given three instances of MyPoint.

5. A toString() function that returns a string description of the instance in the format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".

6. A getPerimeter() function that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.

7. Also write a test program (called main.cpp) to test all the functions defined in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).

class MyTriangle {
MyPoint v1;
MyPoint v2;
MyPoint v3;

public:
MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3) {

[Code] .....

View 3 Replies View Related

C/C++ :: Area Of Triangle Calculator?

Nov 16, 2014

I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />

#include "stdafx.h"
void main()
{
int a,b;

[Code]....

I get this errors:

-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data

View 4 Replies View Related

C/C++ :: Calculating Hypotenuse Of A Triangle

Apr 3, 2014

I wrote a function to calculate the hypotenuse of a triangle. My code looks fine but when i enter the two sides it does not give out the right answer. I really don't know what to do.

#include <stdio.h>
#include<Windows.h>
#include<math.h>
double hypotenuse(double side1, double side2);
int main(void){
double side1, side2, hyp;

[Code] .....

View 8 Replies View Related

C/C++ :: How To Tell If Point Is Inside Triangle Or Outside

May 13, 2014

So, I have created a class called "point" and i have 4 "point" objects. They only have 2 variables, x and y (their position). The first 3 points form a triangle and now I need to tell if the forth one is inside or outside. I have found some solutions but they involve heavy math (they are based on the sum of the angles or something like that). I want to know if there is any way to solve this only by using the distance between points. I have created a function which takes 2 "point" objects and returns a float value which is their distance.

Here is some code:

#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;

[Code]....

View 5 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols

Jan 1, 2015

I'm making a program that prints a triangle of @ signs given rows (but not columns).

For example, the output with rows = 4 would be:
@@@@
@@@
@@
@

and rows = 3 would be:
@@@
@@
@

However, trying to make this has given me a program that does something similar (but not the same):

for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@

and rows = 3 gives
@@@
@@
@

It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:

1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.

My current code is:

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;

[Code] ....

I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?

View 4 Replies View Related

C++ :: Program That Prints Out Pascal Triangle?

Jan 20, 2015

I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:

Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

[Code]....

View 3 Replies View Related

C :: Print The Star Equilateral Triangle

Dec 23, 2014

I use photos to express it. The answer is:

Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {

[Code]....

View 3 Replies View Related

C :: Calculates Area Of A Triangle - If Statement

Jun 10, 2013

I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.

I am using Heron's Formula. Here it is for reference:

area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2

Code:
#include <stdio.h>
#include <math.h>
int main () {

float area, sideA, sideB, sideC, halfP;

[Code] ....

View 4 Replies View Related

C++ :: Program To Calculates Hypotenuse Of A Right Triangle

May 12, 2014

How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far

#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;

[Code] ....

View 4 Replies View Related

C++ :: Triangle In Nested While Loop Using Counters

Mar 13, 2013

How to make triangles using c++, in nested while loops.

The triangles were:
*
**
***
****
*****
******
*******
********
*********
**********

I have made a code for this:

int counter=1;
while (counter<=10){
int counter2=1;
while (counter2<counter){

[Code] .....

I was not quite sure about this one.

View 5 Replies View Related

C++ :: Program To Find Area Of Triangle?

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

C++ :: How To Display Pascal Triangle Using 2D Array

Aug 16, 2014

how can i display a pascal triangle in forloop?

Here's my code.

#include<iostream>
using namespace std;
void print(int a[3][3])

[Code].....

View 1 Replies View Related

C++ :: Print Equilateral Triangle With Asterisks?

Feb 22, 2013

how can i print an equilateral triangle with asterisks .

View 3 Replies View Related







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