C++ :: Hailstone Sequence - If Else If Loop

Aug 22, 2013

My assignment is to write a program that reads in a number from the user and then generates the hailstone sequence from that point. I'm not sure if I should use an if statement or string loop. The beginning of an attempt

#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> Numbers;
/// if n is equal to 1 the sequence has ended
/// if n is even divide the number by 2
/// if n is odd, multiply by 3 and add 1 to new number

[Code] ....

View 2 Replies


ADVERTISEMENT

C++ :: Getting Longest Sequence In Hailstone Program

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

C++ :: Getting Incomplete Sequence

Jan 14, 2014

unsigned char x1, x2, x3;
size_t ix = 0;
size_t count;
std::string Input = "EFEF9E9475C8C2D938C204EAE058F2B3";

[code]....

when debug and have a watch on out i get incomplete sequence,

View 8 Replies View Related

C :: Fibonnaci Sequence Function

Mar 6, 2013

Code:

int main()
{
int n;
int* fib;
printf("
Fibonacci test 1: enter an integer
");
scanf("%d",&n);
fib = fibonacci(n);
printf("fib(%d) = ", n);
for(int i = 0; i < n; ++i){
printf("%d ", fib[i]);
}

What should I do/write for the fibonnaci function Code: int fibonnaci(int size)

View 7 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++ :: 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++ :: Finding Nth Number Of A Sequence?

Sep 16, 2013

I have to write a program to find the nth number of the Ulam numbers.

It's a bit complicated to explain what an Ulam number is but Wolfram explains it very well here: [URL]

I have to find the nth Ulam number but I don't know what I have to do to get that. My program gives me all the Ulam numbers from a range of 0 to n.

What I want the program to do is tell me that the 49th Ulam number is 243.

/*
C++ Program to find nth Ulam Number
*/
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int num = 0;
vector<int> v;

[code]....

View 4 Replies View Related

C/C++ :: Printing Out Arithmetic Sequence

Oct 6, 2014

I made a program that prints out arithmetic sequence.. but problem is that,

when I enter a(first term) =5, d(differnce)=2.4 and n=3 the program prints out only first two terms not three.. for all the other numbers it works correctly..

View 1 Replies View Related

C++ :: Number Of Sequence In Array?

Apr 24, 2013

I am trying to write a program that checks whether the number is in sequence(as in if the numbers are in order it is a sequence). Ex: If the numbers are {1,2,3,6,7,8,9,10,11,13,15,17,20,21}, then, the underlined parts are a sequence. Now i want to find

1) the no of sequence in the array(in the above it is 3 )
2) the longest sequence (7to 11 which is 5).

View 2 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

C :: Warning - Unknown Escape Sequence

Feb 2, 2013

I'm doing some file input/output work here in C and received this warning during compilation (GCC). My research indicates that this error is in response to white space or a character cancellation function or something like that. I'm not 100% sure exactly what it means. My code works fine, but the following warning does appear.

Code:
warning: unknown escape sequence: '40'

Here's my code (excluding a bunch of comments at the bottom of the file).

Code:
#include <stdio.h>
int main(void){
FILE *file;
file = fopen("Running Practice.c", "a");
fprintf(file, "Testing...
");
fclose(file);
}

I believe the error I received has to do with either the ' ' I used when appending text to my file, or something to do with there being a space in the file name itself.

View 6 Replies View Related

C# :: Give Image Name As Sequence Number?

Nov 18, 2014

I'm saving the images in folder by using:

webClient.DownloadFile(href, sourcepath);

I don't want to give name as Current date and time..shown in given below code

string sub = @"Gadhada";
DirectoryInfo subFolder = dir1.CreateSubdirectory(sub);
Imagename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +

[Code].....

I want to save my imagename as 1.jpg, 2.jpg, 3.jpg.

View 1 Replies View Related

C/C++ :: Side Effect In Sequence Point?

Nov 4, 2014

A sequence point in a C program is defined as "Any point in a program's execution at which it is gauranteed that all side effects of previous evaluations will have been performed and no side effects from subsequent evaluations have yet been performed."

What is a side effect?

View 7 Replies View Related

C++ :: Calculate The Nth Number In Fibonacci Sequence

Feb 28, 2013

I was trying to create a code to calculate the nth number in a Fibonacci sequence, when the nth number is entered interactively.

View 4 Replies View Related

C/C++ :: Calculate Sum And Average Of A Sequence Of Numbers

Feb 17, 2014

Write a C program that calculates the sum and average of a sequence of numbers. Assume the first number specifies the number of values remaining to be entered. If the first number is less than 1, then the program should display an "Invalid Entry ... Please enter a positive number." message.

THIS IS HOW IT SHOULD COME OUT...
Enter the number of values to process 0

Invalid Entry ... Please enter a positive number.

Enter the number of values to process 3
Enter 3 numbers:
1
2
3

Sum: 6
Avg: 2

THIS IS THE CODE I HAVE SO FAR...

#include <stdio.h>
int main(void) {
int total=0;
int howmany;
int i;
int value;

[Code] ....

View 8 Replies View Related

C/C++ :: Sequence Class With Linked List?

Apr 10, 2014

my data structures and algorithms professor gave us the following assignment. We are to reimpliment a class we wrote earlier in semester called sequence(which holds a sequence of floats) using a linked list. However I am having trouble with the class's copy constructor and assignment operator, specifically when the sequence is not empty.

links to google drive files

node
node header file
test program
sequence implmentation
sequence header file

View 10 Replies View Related

C/C++ :: Using Functions Storing Sequence In Array

Oct 4, 2014

Trying to make a program that stores a sequence of integers in an array by using functions. This is my code so far:

# include <iostream>
using namespace std;
int Sequence_Length(int seq_length)
{

[Code]....

I get an error in the main, not completely sure how to "call" functions to the main..

View 5 Replies View Related

C/C++ :: Swapping Of Position Of Elements In A Sequence

Oct 24, 2013

Write a program that gets a sequence of unsigned integers.the user can enter at most 100 integers.

After getting the numbers, the program allows the user to repeatedly choose one of the three options:

1. swap the location of two entries in the sequence. if this option is chosen the user is prompted to enter the two locations to be swapped.

2. print out the sequence.

3. repeatedly swap two locations in the sequence until getting back to the state before this operation started. then print out the number of swaps performed.

View 3 Replies View Related

C/C++ :: Fibonacci Number Sequence Implementation?

Jun 19, 2013

I need to implement the fibonacci number sequence. Here is an example output of the program:

Server:Waiting for connection
Server:Receive connection from client
Client:10
Server:Print 10 Fibonacci
Server:1 1 2 3 5 8 13 21 34 54
Client:1 1 2 3 5 8 13 21 34 54

if Client send value of 5, the output would be 1 1 2 3 5

View 2 Replies View Related

C++ :: Determination If Sequence Is Increasing Or Non-decreasing?

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

Visual C++ :: Search Technique On DNA Sequence

May 10, 2013

Given a set of DNA string. Find minimum length string S so that, given DNA strings are subsequence of S.

For example, if given set of string is: {CAGT, ATGC, CGTT, ACGT, AATT} then answer is: 8. Because, ACAGTGCT contains all given DNA as subsequence.

Given n such DNA string (n <= 8), each of length atmost 5. Find out the least length.

Sample:
5
AATT
CGTT
CAGT
ACGT
ATGC

Output:
8

View 2 Replies View Related

C++ :: Program Doesn't Read The End Of File Sequence

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

C++ :: Program That Reads In A Sequence Of Binary Digits?

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

C++ :: Create Fibonacci Sequence With Some User Inputs

Aug 26, 2013

I'm trying to make a fibonacci sequence with some user inputs. I'm using arrays for this, the user inputs are for the Nth term and the starting number (as in the number in front of 0).

My problem is that when the program runs it's an infinite loop which constantly prints the starting number. Which, I think, means that my WHILE loop isn't coming to an end and my 'count' variable isn't increasing.

#include <iostream>
using namespace std;
int main() {
int start;
int term;
cout << "Input a starting number for the sequence: ";
cin >> start;
cout << "
Enter the Nth term for the sequence to reach: ";

[code].....

View 4 Replies View Related

C++ :: Sequence Of Actions - Delete Pointer In Vector

Jul 29, 2013

I'm tying to create a program that evaluates all possible actions for a certain problem.

So what i'm basically trying to do is to create a sequence of actions, evaluate them to check if it's the best sequence, change the sequence, evaluate again and so on until all possible scenarios are exhausted, leaving the best one in the end.

My approach to this at first was to create a tree of all possible options and then evaluate each branch. Since there are a lot of possible cases i ran out of memory while the program was still creating the tree. I changed this to create just a branch, evaluate it and then modify it.

I was still getting memory problems. I declared a class tNode and declared a vector<tNode*> branch. Then i created all the nodes i needed for that branch with branch.push_back( new tNode() ). When i wanted to modify the branch i simply used branch.pop_back() and again a branch.push_back( new tNode() ). I figured i was getting the problem because although i clear the vector, i don't actually clear the reference in memory. Is this correct? If so, how can i actually delete the memory space and not just the pointer in the vector?

View 6 Replies View Related







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