C :: Program That Returns Pascal Triangle Of N Rows

Nov 25, 2013

I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.

Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));

[Code] ....

View 7 Replies


ADVERTISEMENT

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++ :: 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 :: How To Check If Return Value Actually Points To Pascal Triangle

Nov 27, 2013

I have been trying for hours to create a specific prototype program that determines a pascal's triangle for a give number of rows. However, prototype must have the return type of int**. I just recently learnt about pointers, why my attempt of the function doesn't work. As well, i am not sure how I can check if my return value actually points to the pascal triangle.

Code:

#include <stdio.h>
#include <stdlib.h>
int **getPascalTriangle(int n)
}

[code]....

View 1 Replies View Related

C/C++ :: Print Pascal Triangle Based On Integer N Inputted

Nov 7, 2014

void Pascal(int n){
int i,j;
int a[100], b[100];
a[0]= 1;

[Code] ....

I've been trying to make a function that prints a pascal triangle based on an integer n inputted.

View 3 Replies View Related

C :: Print Pascal Triangle And Stores It In A Pointer To A Pointer

Nov 27, 2013

I have to write a program to print pascals triangle and stores it in a pointer to a pointer , which I am not entirely sure how to do. I also have to write the file and read it, then create a binary file. Assignment is attached. I am not the best with programming and especially with pointers. I will post my code below.

Code:
#include <stdio.h>
#include <stdlib.h>
void writePascalTriangle(char *fileName, int heightOfTriangle, int **triangle) {
FILE *fp;
fp=fopen("writePascalTriangle.txt", "w");

[Code] ....

View 4 Replies View Related

C :: Drawing Hollow Triangle Given User Input Indicating Number Of Rows

Oct 4, 2014

How to draw a hollow triangle given a user input indicating the number of rows.

Eg:
Number of rows = 4
___*
__*_*
_*___*
*******

My idea was to split up the triangle into three parts (first row, middle part, last row) and I've managed to write some code on printing the first and last row of the triangle

Code:
int main() {
//Declaring the variables.
int rows, position;
//Prompts user to enter number of rows.
printf("Enter the number of rows in the triangle: ");
scanf("%d", &rows);

[Code] .....

What to do so that I can print the middle part of the triangle. All I know is that I need to use loops. I've also been told that drawing a flow chart would work but I really don't know how to even begin with a flow chart then transform it into code.

View 2 Replies View Related

C :: Program That Return Value Of A Function That Returns Price

Oct 24, 2013

I'm writing a function that is to return the price of something.. What would be the most appropriate return type for this? Like in Java it would be a double...

View 6 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 :: Program Crashes And Returns Random Negative Numbers

Mar 1, 2014

I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.

Code:
/* Evan Wentz */
/* Pike - ET2560 */
#include <stdio.h>
#define MAX_ACCTS 100

int accounts [];
double balances [];

[Code] ....

I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...

View 6 Replies View Related

C/C++ :: Program To Sum Rows And Columns Of A Matrix?

Apr 23, 2014

Im using apmatrix and im inputting values into a 4 by 4 matrix and im getting all these errors that have nothing to do with my cpp file so im guessing its apmatrixies fault. Also I put in the cpp and header file of both apmatrix and apvector into my project folder. Heres my code:

// Libraries
#include "apmatrix.h"
#include <iostream>
//cout, standard output
// <<, stream insertion operator

[code]....

My errors are:

error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning C4005 to find the forbidden macro.c:program filesmicrosoft visual studio 11.0vcincludexkeycheck.h2421TheMatrix

4IntelliSense: identifier "EMIT" is undefinedc:Program FilesMicrosoft Visual Studio 11.0VCincludeyvals.h4911TheMatrix

and a bunch are repeated

View 1 Replies View Related

C# :: How To Get Program To Keep On Adding Rows To Datagrid

Jul 6, 2014

I want to be able to keep on adding a row to my datagrid every time i click a button, the row will hold the text of the text box and the combobox in its individual cells, is there a way to do this without inserting a ridiculous amount of code?

Attached image(s)

View 1 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 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++ :: 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 Modify A Program So That It Accepts Columns Instead Of Rows

Feb 4, 2015

I have a N queens (actually 8 queens to be specific) program that accepts the numbers in order by row. I need to get it so it accepts the numbers in order by column. At first glance I thought it was just one space different, but it turned out not to be and how to get the one space difference in there. My current code (which I'm aware isn't doing the column accepting right) is:

Code:

#include <iostream>
using namespace std;
int main() {
int board[8];
cout << "Enter the columns containing queens, in order by column: ";
for(int i = 0; i < 8; ++i) {
cin >> board[i];

[Code]...

What the output should be:

Code:

Enter the rows containing queens, in order by column:

7
6
5
3
4
2
1
0

.......Q
......Q.
.....Q..
...Q....
....Q...
..Q.....
.Q......
Q.......

What it is:

Code:

Enter the columns containing queens, in order by column:

7
6
5
3
4
2
1
0
........Q
.......Q.
......Q..
....Q....
.....Q...
...Q.....
..Q......
.Q.......

View 5 Replies View Related

C++ :: Program That Prints A Triangle Of Symbols In A Certain Direction

Jan 12, 2015

So I need to make a program that prints a triangle of symbols in a certain direction.

For example: Code: How many rows? 3

@
@@@
@@@@@

How to do that. It's rare that I post without figuring anything out, but I'm just simply not sure. I have a program that prints a triangle in a similar direction, so maybe if I could get some hints as to what to do with that (HINTS, not direct source code) .

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

[Code] .....

View 6 Replies View Related

C/C++ :: Right Triangle Program - Computing Lengths Of Sides

May 5, 2014

I made a simple program to compute the lengths of a triangles sides, but when I enter 30 for angle and 10 for hypotenuse I get the opposite side is -9.880316 and the adjacent is 1.542514.

#include <stdio.h>
#include <math.h>
main() {
float angle;
float hypotenuse;
float adjacent;
float opposite;

[Code] ....

View 2 Replies View Related

C :: Two Stumbling Blocks - Determine Size Of Rows To Create In Program

Apr 18, 2014

Working on an assignment and I've hit TWO stumbling blocks. I now have to take the first line from a .txt file and use that number to determine the size of rows to create in my program. I am using fscanf but the program hangs. How can I read in this number, store it and use it in a for loop?

The second issue is after reading this number I have to print each number in the .txt file under a different column. (Note that it skips a line after reading the row count.) The .txt file is set up as follows:

9 1 3 6 4 7 8 8 6 1

The output should look sort of like:

Number ​1 3 6 4 7 8 8 6 1

Here's my attempt:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>

typedef struct{
int number;

[Code] .......

View 2 Replies View Related

C++ :: Program Inputs The Number Of Rows And Columns And Asks For The Entries

Feb 7, 2015

I am writing a program that deals with 2d arrays. The program inputs the number of rows and columns and asks for the entries. When the program run and compiles it works perfectly until it outputs then it gives me a warning.

Here is my code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int row1=0,col1=0,i,j;
//int a[row1][col1];
int** a= new int*[row1];

[Code]...

I am learning how to do this before I can move on so it can read a text file of numbers.

Also I am having problems with ////delete [] a[];///// I took it out because it made my code compile and run but when I add it in, it gives me an error:

matrixtesting.cpp|56|error: expected primary-expression before ']' token|

I know this expression is suppose to deallocate the array.

View 7 Replies View Related

C++ :: Program That Will Represent Axis-aligned Right Triangle In X-y Plane As A Class

Apr 10, 2013

I am having trouble of exactly how "class" works. I dont know what the difference between set and get is. I have this code:

#include <iostream>
#include <cmath>
using namespace std;
class Point {
private:
double px;
double py;

[Code] .....

How to get void Triangle::setBottomLeftX(const double x) to work.

Implement the get and set member functions for the class Triangle. Use the appropriate class attributes of the class Triangle.

a. The location of the bottom left vertex is stored in the member attribute blPoint.
b. The top left vertex can be computed from blPoint and the height.
c. The bottom right vertex can be computed from blPoint and the length.

View 19 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

C++ :: Getting Too Big Of Numbers On Returns

Feb 7, 2013

I am trying to get each step down before proceeding to the next one for my problem. I have started my program into returning the Area and Volume of a cylinder. The return numbers I get are huge and I cannot figure out why.My header file

class cylinderType {
public:
void getRadius(double rad);
void getHeight(double heigh);
double area();
double volume();

[code]....

View 17 Replies View Related

C :: Function That Returns A Char

Sep 4, 2013

I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.

Code:

//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;

[Code].....

View 11 Replies View Related

C++ :: Functions With Void Returns?

Nov 27, 2014

Write a C++ program consisting of main plus two other functions which will do the following:

Take an integer input from the keyboard.

Send the integer to a function which will output the integer to the screen.

Send the integer to a second function which will tell the user that the integer is an odd value.

Do not tell the user anything if the integer is an even value.

Repeat this process until the user enters something which is not an integer; use input validation to check for validity.

Any not valid input should terminate the program.

View 3 Replies View Related

C++ :: Minesweeper - Function Always Returns The Same

Jun 24, 2013

For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:

bool setzen(int x, int y){
if(feld[x][y]!=3){
return mine=false;
}

[Code]....

Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.

View 6 Replies View Related







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