C/C++ :: Write A Function Fibonacci That Takes Int Indicating Length

Sep 2, 2014

We have to write a function named fibonacci that takes an int indicating the length of the series and then store it in an array of size 20 printing the sequence from largest to smallest. Here is the small bit i have so far:

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

[Code] ....

I just need something to get me on the right track.

View 1 Replies


ADVERTISEMENT

C++ :: How To Write A Function That Takes Two Linked List As Input Arguments

Dec 7, 2012

How do I Write a function that takes two linked list as input arguments these linked list contain numbers like this:

num1->3->5->2->NULL (assuming that number 1 is 352)
num2->4->3->9->1->NULL (assuming that number 2 is 4391)

The function should return 1 if num1 points to a linked list which represents a smaller number than the number pointed to by num2 linked list. Otherwise, it returns -1. If both linked list point to exactly the same number, returns a 0.

View 3 Replies View Related

C++ :: Write Function That Takes Array And Returns True If All Elements In Array Are Positive

Jan 21, 2013

Write a function that takes an array and returns true if all the elements in the array are positive, otherwise, it returns false.

View 6 Replies View Related

C++ :: Program Which Takes Input From User And Write It To A File

Jan 15, 2013

A program which takes input from user and write it to a file then it reads data from that file then it should search for specific data such as email adresses or url etc.

View 1 Replies View Related

C++ :: Function That Takes Int As Argument And Doubles It?

Jan 7, 2014

Write a c++ function that takes int as an argument and doubles it.the function does not return a value.

View 5 Replies View Related

C++ :: Pow - No Overloaded Function Takes 1 Arguments

Oct 4, 2013

I keep getting this error in my code. I believe it is because to use pow(x,y) both x and y have to be double, but how do i put that into my formula under calculations?

#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main() {
// Declaration section: Declaring all variables.

[Code] ....

View 4 Replies View Related

C++ :: Indicating A Sequence Of Elements

May 20, 2013

Why is it that in the STL it is standard to indicate a sequence of elements in a container by a begin iterator that points to the first element and an end iterator that points to one past the last element?

View 2 Replies View Related

C :: How To Call A Function That Takes A STRUCT Parameter

Feb 23, 2015

I just want to call the function : outputboo(), but I dont know how

Code: /*Enthusiastic
Pessimism
desensitize
uniqueness
*/
#include <stdio.h>
#include <string.h>
struct Books{
char title[50];
char author[50];

[Code]...

View 2 Replies View Related

C :: Function Which Takes A Character Array And Reverses It

Dec 7, 2013

Write a c function which takes a string(as a character array, null terminated) and reverses it. it doesn't print the reversed string -- it modifies the given string so that it is reversed.

Code:

void reverse(char array[]) {
char tmp;
int i, j;
for(i=0;i<strlen(array); i++){
for(j=strlen(array)-1;j>=0;j--) {
tmp = array[i];
array[i] = array[j];
array[j] = tmp;
} } }

how come this doesn't work?

View 2 Replies View Related

C++ :: Program That Takes Several Numbers Into Array Into A Function

Nov 25, 2014

I have to make a program that takes several numbers into an array into a function, and send them back into the main function multiplied by 1.13. This is what I have so far:

#include <iostream>
using namespace std;
void connell(int&n[20])
main() {
int num[20];

[Code] ...

I do not know how to get numbers from an array from a main program to a function.

View 2 Replies View Related

C++ :: How To Create A Function That Takes A File Object As A Reference Parameter

Feb 21, 2013

I have a school project in which need to create a function that takes a File Object as a Reference Parameter. Supposedly, it should allow me to read the first piece of data from others separated by a space from a file. The later be able to continue reading from the next piece of data.

I know how to set things up to read from the data file, such as using

Code:

#include <iostream> , and

Code:

ifstream inputFileName;
inputFile.open ("nameOfFile");

I also understand how to pass a variable by reference to a function. But I simply cannot put the two items together!

I tried using

Code:

void getFileInput (ifstream &); //parameter
getFileInput ("nameOfFile") // call
void getFileInput (ifstream &dataFileName)

In the function I used

Code:

ifstream inputFile;
inputFile.open (dataFileName);

I'm just not getting an understanding of this concept!

View 4 Replies View Related

C++ :: Function That Takes Two Input Arguments And Provides Two Separate Results To Caller

Apr 20, 2014

Write a function that takes two input arguments and provides two separate results to the caller, one that is the result of multiplying the two arguments, the other the result of adding them.Since you can directly return only one value from a function, you'll need the second value to be returned through a pointer or reference parameter.

Code:
#include "Code.h"
#include <iostream>
#include <string>

double x, y;

[Code] ....

View 3 Replies View Related

C++ :: Program That Takes Baseball Players Statistics And Display Averages - Function Division

Oct 10, 2013

I was required to write a program that takes a baseball players statistics and displays there averages. I was required to make 3 function in the file to perform this tasks. my problem I am having a division problem in the SLG function. My compiler does not require the system ("PAUSE"); command.

OUTPUT
The player's batting average is: 0.347
The player's on-base percentage is: 0.375
The player's slugging percentage is:
(test)AB = 101
(test)Tot Base = 58
0.000

Code:
/* Batting Average Program
file: batavg1CPP.cpp
Glossary of abbreviations:
BA = batting average
PA = plate appearances
H = hits
BB = bases on balls (walks)

[Code] ....

View 3 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 :: Pointer Variable Indicating Memory Location - Volatile Type Qualifier

Jun 26, 2014

If I have a pointer variable indicating memory location in which we have stored what user entered and the pointer is of type volatile if the user gives the character 'a' twice , then this character will not be fetched twice from the memory but only when the character is changed???

This is the one meaning of the volatile? the other is that the value will be changed without the program itself change it?

View 4 Replies View Related

C++ :: Function That Get Length Of Integer?

Nov 23, 2013

Any good function that get the length of an integer in C++

I do know of str.length(), however i want something similar for integers

View 1 Replies View Related

C :: Why To Set Length Of Inner Arrays Declaring A Function

Oct 23, 2013

I'm just wondering, why you have to set the length of the inner arrays declaring a function. In which moment does the code needs to be sure about the length of the inner arrays accessing an cell?

I came up with this question realizing the elements of the outer array beeing pointers to the first value of each inner array. Therefore I can access e.g. the first first element of the second inner array like this:

**(arr + 1) ...regardless of the length of any array to my mind.

parallel post: [URL]...

View 6 Replies View Related

C++ :: How To Obtain Length Of Array That Has Been Sent Throughout Function

Sep 9, 2013

How can I obtain the length of an array that has been sent throughout a function. In the following code, I obtain "2" as output, while I was expecting "5".

void call(int a[]) {
cout<<sizeof(a)/sizeof(int);
}
int main() {
int* a=new int[5];
call(a);
}

How can I properly call this function so I can obtain the correct array size?

View 2 Replies View Related

C++ :: Function To Receives Integer Array Along With Its Length

Apr 2, 2014

How to write a function that receives an integer array along with its length. the function calculates and returns the sum of the squares of all the odd numbers in the array?

View 2 Replies View Related

C++ :: Passing Vector To A Function - Getting Negative Length And Size

May 22, 2013

I am writing a raytracer, and currently I'm working on creating a bounding volume hierarchy to accelerate the process. To do this, I am first creating a vector that holds each of the objects in the scene, and passing this vector to the constructor for my BVH.

Code:
//in header
BVH_Node* bvh;
//in main raytrace function

[Code] .....

I am testing a scene that has only 2 objects, and so it goes to the size == 2 check. The first time it hits makeLeaf(), I segfault. I've used both gdb and valgrind, and of course it's a memory mapping error. gdb's backtrace tells me that the length of the vector I've passed in is -805305610 and the capacity is -21, and that it is inside my makeLeaf() function that the error occurs.

Here's the function:

Code:
BVH_Node* BVH_Node::makeLeaf(GeomObj* v){
BVH_Node* node;
node->obj = v;
node->isObj = true;
return node;
}

The segfault happens at
Code: node->obj = v;
If I run my raytracer without a BVH, the objList works perfectly.

View 8 Replies View Related

C++ :: Send Rectangle To A Function Which Takes A Rectangle Argument

May 13, 2014

Consider I have a rectangle like this:

Point p1(100,100);
Point p2(300,200);
Graph_lib::Rectangle r(p1,p2);

And also I have a function that takes a rectangle and returns a Point of that, say, top-left corner of that rectangle. For example:

Point N(Graph_lib::Rectangle R1);

My question is that, first, how to send that Rectangle r(p1,p2) to the Point N(Graph_lib::Rectangle R1) function? And then, how to return a Point from that function?

My IDE is visual studio 2012.

View 19 Replies View Related

C :: FIbonacci Sequence With Formatting

Sep 2, 2014

I made a fibonacci series with label above it now how to put the label after the first layer because as you can see in the screenshot the label is continuous.

View 2 Replies View Related

C++ :: Fastest Way To Calculate Fibonacci

Apr 1, 2013

What is the most efficient way to calculate Fibonacci. Is it recursion with memorization, is it iteration or is there another approach?

View 1 Replies View Related

C/C++ :: Pi Approximation With Fibonacci Series?

Oct 11, 2014

I can't seem to get the math portion right. It is supposed to approximate pi using (sigma,i=-1 to infinity)(-1)^(i+1)(4/(2i-1))=4(terms of pi). And what I have does some math but it is incorrect because I get a negative value for pi and one that is entirely too large at that. The precision is also to be at 20 decimal places. I also need it to end immediately after if I get an invalid input, but I can't seem to get it to end after trying a few different things it will say that it is an invalid number, but will continue to run the math loop. I also need the final cout to print all the terms that is multiplied by 4.

[code]#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int nterm, numerator;
double sum = 0.0;
const int upperBound = nterm * 2;
cout<<"This program approximates pi using an n-term series expansion. "<<endl;

[code]....

View 11 Replies View Related

C/C++ :: How To Do Fibonacci Sequence Program

May 5, 2014

Q) How to do nested loops?
Q) How to do Array?
Q) How to do Fibonacci sequence?

View 1 Replies View Related

C++ :: Sequence Of Fibonacci Number

Feb 16, 2014

The next code is right. I mean it works. It gives the sequence of fibonaci numbers ...

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

if(!pos)return 0;
if(pos==1)return 1;

[Code] .....

But.... when I change the lines:

Code:
int r1=fibo(pos1);
int r2=fibo(pos2);
int r=r1+r2;

For the lines:

Code:
int r=fibo(pos1)+fibo(pos2);

It doesn't work right. Apparently it should work the same.

View 11 Replies View Related







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