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.
I am working on a problem that requires a nest for loop to be converted to a recursive function. I am going to provide just the code instead of the entire program.
Code:
for (R1=1; R1 <+3, R1++){ //for loop printf (something); } // the recursive function void loopR1 (int R1, int max){ if (R1 <= max){ printf (something);
[Code]...
when calling the recursive function in main i am using the following statement...
at this point run a loop for all players, in this loop use random to determine the face and depending on the face run a loop (for roll again etc) or give next user the chance.
And this loop is 2-12 people, all rolling die. They draw 3 die out of a cup of 12. Then they roll the 3 die, getting fish, hook, or boot on each die.
Write a program to make a table for any input number and then continuesly ask to press y to print more table and if you press any key other than y then program must be terminate using while loop and do while loop. How to start or end with it.
I am trying to create a recursive function that i can call on in order to take a user inputed base and exponent and give final answer this is what i have but im completely lost after this i dont even know how to continue. What i have so far
#include <iostream> using namespace std; int Exp(int x,int y){ if(base <= 1 || exp == 0) return 1; if(exp == 1) return base; int main(){ int number, exp;
[Code] .....
After i set the base situations im not sure how to get the function to make the function take the base to the exponent recursively.
Why my program is returning a negative number at the end...attached is the program:
/*Write a recursive function recursiveMinimum that takes an integer array and the array size as arguments and returns the smallest element of the array. The function should stop processing and return when it receives an array of 1 element.*/
#include <stdio.h> #include <time.h> #include <iostream> using namespace std; float recursiveMinimum (int ARRAY[], int n);
When I worked with Fibonacci it was pretty easy since I just had to decrement the next member for each step. I used the following:
#include <stdio.h> #include <stdlib.h> #define MAX 100 int fib(int n) { static int memorize[MAX] = {1,1}; if(memorize[n]) return memorize[n];
[Code] ....
My main problem is that I have no visual of the current function, as well as the fact that it takes the f(n+3) = f(n+2) + f(n+1) + f(n), whilist I've only got f(n) to begin with.
0. Base Case: If the number is one digit long, we don't want to erase it (by returning 0). Instead, riddle me this: When I have a one-digit number, what happens if I change all the 7's into 8's? Well, if the number is 7, it becomes 8, but otherwise it's unchanged.
1. Recursive Call: If the number is longer, then we strip off the last digit, figure out what the answer for the rest is (the recursive call on n/10), and then put the last digit back on the number when you're done.
Hint: You probably need to store the least digit (the n%10) and check if it's 7 separately.
#include <iostream> using namespace std; int removeFirst(int n) { if(n<10) return 0; return 10*removeFirst(n/10)+n%10;
How do i make the srand() function make new numbers every time i call it? Now it seems like it repeats its result over an over again.
Below is a program that should generate random numbers for 3 dices and print these out. But it prints out the same nr over and over.
Code: #include <stdio.h> #define MAX 100 int filler(int dice1[MAX], int dice2[MAX], int dice3[MAX]) { int throws, nr; printf("Define the number of throws"); scanf("%d", &kast);
I have a class called items and stored in a vector as vector<items*> item.now I want to make a function to return the placement # that the item is stored at with a unsigned int. but if I don't find the item is there like a null unsigned int that can be returned.
unsigned int someFunc(vector<items*> item) { unsigned int size = item.size(); for (unsigned int i = 0; i < size; ++i) { if (item[i]->getItemName() == "sword") { return i; } } //i need code here incase the item is not there }
because the item might not be there and i would like to do a line if(unsigned int) do this code
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.
I'm trying to write a program for a lab, I know how easy it is but cant see to crack it.
I need to make a program using while or for loop.
I must have the user type a number, for an input value an output value but then do it again several times but without it going on forever asking again and again.