C++ :: Program That Uses Recursion To Find Longest Increasing Sequence From A Grid In File
Mar 25, 2013
Any examples of a c++ program that uses recursion to find the longest increasing sequence from a grid in a file. Like
2 4 6 8
10 12 14 16
18 20 22 24
I have to use a structure named Point and a structure named Sequence.
const int MAXROWS = 4;
const int MAXCOLS = 4;
const int MAXFILENAME = 255;
// Structure used to define a point (x,y) in the grid.
typedef struct {
int x, y;
[Code] .....
View 1 Replies
ADVERTISEMENT
Oct 4, 2014
The following is a part of a hailstone cpp program. I want to write an option to let users enter 2 numbers and the program evaluates the longest sequence the number has within the 2-number range and return the count.
Code:
int longestHailstoneSequenceLength(int start, int end)
{
int max = 0;
int s= start;
while (s!=1)
[Code] ....
View 8 Replies
View Related
Dec 6, 2014
Code:
#include <iostream>
using namespace std;
int j;
int n;
int recursive ( int arr[j] );
int main() {
int i;
int arr[10000];
[code]....
This is how I tried making the program..
I want it with a recursive function
I want if the sequence is non decreasing return true else return false
View 10 Replies
View Related
Jul 3, 2013
Currently I am working on a program that will find the actual distance between two points on a grid. It also determines the angle of the line segment in degrees. Now, i need it to be able to find any other points on or near the line. It will be running in a loop to find each additional point sequentially until all the points have been plotted. Unfortunately, I am not entirely sure how this is done. So far, I think that I could develop an algorithm that converts the angle into a ratio of vertical movements to horizontal ones.
View 7 Replies
View Related
Feb 27, 2014
I am trying to make a program into which you writre for example ten Names or words or etc. and it would find the longest name/word write it and the numbers of characters too but I have problem with displaying that name. Here is me source code, the problem is here "vitaz=szInput;" i don't know how to save that longest name/word.
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int main () {
char a;
char szInput[256],vitaz[256];
[Code] .....
View 5 Replies
View Related
Apr 29, 2015
How to find the last longest word in a string when there are more of them (with the longest size)?
Here is the program for the longest without checking if last:
#include<stdio.h>
#include<string.h>
int main() {
char a[50],b[20],c[20];
int i,j=0,l=0;
printf("Enter a string:
");
gets(a);
[Code] ....
View 6 Replies
View Related
Mar 6, 2015
Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)
Here is the code:
Code:
#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}
int positive(int x) {
return x>0;
[Code]...
My question is how to write this code if the prototype of function is:
Code: void series(int *array, int n, int (*s)(int), int **begining, int *lenght);
View 1 Replies
View Related
Mar 16, 2015
program:
Example input: 2 4 6 -1 7 3 -2 1
Output: 3 3 (longest series of even is 3, longest series of positive is 3)
Here is the code:
#include <stdio.h>
int even(int x) {
return x % 2 == 0;
}
[Code].....
My question is how to write this code if the prototype of function is:
void series(int *array, int n, int (*s)(int), int **beginning, int *length);
View 1 Replies
View Related
Feb 9, 2015
I am new to C++ programming, writing a program for the below question:
given a string, how to find the longest substring with all unique characters.
View 1 Replies
View Related
Aug 16, 2014
i have a question, i'm studyng the string library type and i have to write this program :
Code:
std::string word;
while (std::cin >> word) {
std::cout << word << std::endl;
}
why if my input is :
hi my name is ^Z
the output is :
hi
my
name
is
why the program doesn't fall out from the while loop ?
why my program does not recognize my sequence of end of file ?
View 5 Replies
View Related
Jan 26, 2013
Write a program to read in a sequence of examination mark from a text file named as input.txt and produce the mean, and standard deviation of the marks. Your program should also produce a bar chart for each grade where the range of mark is given as below.
GradeMarks Range
A80-100
B70-79.9
C50-69.9
D40-49.9
F0-39.9
Output the result to another text file named as output.txt.
View 3 Replies
View Related
Mar 27, 2014
I have to made a programme which will search for given number and it must work in O(log(n)). The problem is that this programme beside finding this number have to find how many times this given number is used in this sequence.
Sequence is from lowest to highest only one possibility to use binary search algorithm
For example when we have squence
-1 -2 3 3 3 3 4 5 6 7 7 8 9 9 9 9 10
The numbers we need to search are
1 , 3 , 7 , 9 , 11 , 12
The answer is
0 , 4 , 2 , 4 , 0 , 0
So we need to find the sum of used number in sequence.
I have written algorithm Code: int start = 0;
int end = sequencelenght - 1;
int mid = 0;
/// Binary serach
while (start<=end) {
int mid=(start+end)/2;
if (sequence[mid]==givennumber) {
[Code] .....
As u see i search for given numer with binary with O(log(n)) but when i have to sum the duplicates the only good way i see is using loop to right and left but this have got log(n) specification (because when sequence would be for example 7 7 7 7 7 7 7 7 7 and given number to search will be 7 this will be O(n) loop).
How would look the most optimal algorithm look for this exercise? I mean O(log(n)) the fastest algorithm....
View 6 Replies
View Related
Sep 12, 2014
I found this implementation on a website for printing the longest common subsequence. But it gives wrong answers for some reason even though the code seems right to me.
Here is the code:
#include <iostream>
int lcs(char *X, char *Y, int m, int n)
{
int L[m+1][n+1];
for(int i = 0; i<=m; i++)
[code].....
What is wrong with this code?
View 7 Replies
View Related
Nov 9, 2014
I put some checks in factorial program, I am confused how 27, 40 50 is coming in output and ans is 10.
#include<stdio.h>
int fact(int n) {
if(n==1) {
printf("hello1 %d
",n);
return 1;
[code].....
View 2 Replies
View Related
Aug 27, 2014
Write a menu driven program that will fill grid with values between 1 and 100. Begin the program by declaring a array of type int. Then present the user with the following menu
Enter 1 to add
Enter 2 to edit
Enter 3 to delete
Enter 4 to search
Enter 5 to display
Enter 0 to Quit
Each item of the menu must be implemented as a function. The program should Only allow values between 1 and 100
Always ask the user to apply coordinates for the cell to be changed
Flag an error when try to delete or edit a cell with a zero (0)
Flag an error when try to add to a cell that is not blank
Display the complete and nicely formatted grid when option 5 is selected
View 2 Replies
View Related
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
Jul 31, 2014
program for counting vowels in a string using recursion ?
View 12 Replies
View Related
Mar 12, 2015
So Im trying to make a program that completes a binary number and I have to use Recursion. Heres an example:
1] ./binary_string.out 01x0
0100
0110
2] ./binary_string.out xx
00
01
10
11
Here's what I got so far but Im stuck and I don't know what's wrong/what to do.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* convertString(char *c,int len);
int main(int argc,char *argv[]) {
int i,length;
char *cs;
[Code] ....
View 2 Replies
View Related
Apr 4, 2013
I'm required to write a program to print out all booms allowed requests below:
1. User will enter the address of the cell and its value.
2. Print out all booms.
How to solve it by using recursion.
View 4 Replies
View Related
May 11, 2013
c++ program that reads in a sequence of binary digits (values 0 and 1) and stores them into a STL container. The input should terminate on any input that is not a 0 or 1. After finishing the read-process, apply a "bit-stuffing" algorithm to the container. In this case the bit stuffing should occur after four consecutive bits of the same value.i,e. four 0's or four 1's.. Also write the de-stuffing code to process the stuffed data to recreate the original data and verify that the original data is recovered correctly.
View 6 Replies
View Related
Apr 3, 2015
I wrote this code to search words in the file and display if the program found the word or not. when i write the words in the file on the same line (without the endl) like this :
w_toFile << "gilbert";
w_toFile << "lara";
w_toFile << "rana";
i can search any word.
but when i write them with the endl, the program can find only the first word. what can i do to make the program find any word even if they are each on a line?
here is the full code:
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main (void) {
string wordsearch;
[Code] ....
View 5 Replies
View Related
Apr 28, 2013
It seems that boost's file recursion requires that the file using the recursion must be in the include path. This makes using file recursion in a library header a problem as libraries may be located in a subdirectory of an include path (which is minor since the programmer can state the subdirectory in the recursive file call as long as it is not relative to the calling file). I also found it a problem when the main compile directory isn't in the compile path.
View 9 Replies
View Related
Jan 2, 2013
Why do i get this error?
View 4 Replies
View Related
Mar 24, 2014
write a program in c to read a sequence of N integers and print the number that appears the maximum number of times in the sequence.
View 1 Replies
View Related
Oct 10, 2014
Im having trouble on getting the quantity up of the variable "item.iqty". For example the current quantity is 5 and in this function, the user inputs a number and it should add to the variable "item.iqty". So if if the user inputs 2 then the current quantity should be 7 now but in my program it hasnt changed. its still 5
void addQty(FILE *fp)
{
int num, qty, r, c, n;
bool found;
[Code]....
View 3 Replies
View Related
Sep 5, 2014
I'm trying to implement a linked list using my own node class. I've created functions to add to the head and tail, return the size of the linked list as well as the value stored within the current pointer.
However, my problem is that when I wrote a test program to see whether my list worked, my list did not appear to increase in size past 1 item in the list.
this is the test program I wrote:
int main() {
int counter,
data;
linkedlist *my_list = new linkedlist();
cout << my_list->size() << endl;
for (counter = 0; counter < 5; counter++) {
[Code] ....
I'm sure it's probably something simple that I've overlooked . But I'm still relatively new to the concept of dynamic memory allocation.
View 2 Replies
View Related