You probably have noticed that after the first two digits each succeeding number is the sum of the previous two in the series.
Also that the client number could be used in a loop condition
to stop it entering further sums (n) + (n-1) into an array.
User Profile
Collapse
-
From Nepomuk's last post.
"it HAS TO at least be scanned and used in some way."
Why?... if it is not required to establish the value of P or S it must be redundant or similar.
By the way tail_recursiven ess is explained (defined) in the reference you provided which is said to be allied to the iterative concept and only a special case of the function which calls itself.Leave a comment:
-
What Nepomuk says is not quite right. 'k' is not required to find the factors of P using tail recursion. For example 48 yields factors 2 2 2 2 3 which sums to eleven as required. k=3 says combine the first two and second two factors to produce 3 4 4 which again sums to eleven.
Here is some code which find factors which may assist in finding your own errors.
Code:#include<iostream> using namespace std;
Leave a comment:
-
I think you would need to know the longitude of the e.s.t. location to calculate ut (the old GMT)Leave a comment:
-
When you reserve memory using 'new' for say an object,the object is essentially nameless however its address is held by the pointer to which it is assigned...I think.Leave a comment:
-
-
-
whodgson replied to use of modulus operator: how can we use modulus operator with double type variablesin CWell one of my books suggests that fmod() can be used with floats and doubles to obtain a remainder. e.g.:Code:cout<<fmod(7.6,2.5);//prints 0.1.
Leave a comment:
-
Another way which I think closely mirrors weaknessforcats algorithm is:
1.)get the number with cin>>
2.)mod(%) the number with 10 to get the least significant digit as the remainder and store it somewhere.
3.)divide the number by 10 to lop that digit.
4.)repeat 2.) and 3.) until digits exhausted
5.)your store is now full of individual digits.
6.)fill a container (array or vector) with the ten digit names...Leave a comment:
-
@swapnali143
The OP said she/he was writing code in C++ so its not particularly helpful to provide complete C code for the task.
(in fact this forum frowns on the practice of providing complete coding solutions because of adverse learning benefit to the OP)
Also a statement by definition ends with a semicolon (;) so as weaknessforcats suggests its absence is one likely cause.Leave a comment:
-
swapnali143 Why wouldn't you:
Code:unsigned int a; for(a=1;a<=INT_MAX;a+=2) cout<<a<<" ";
Leave a comment:
-
Could you create the array dynamically at run time using new and delete?Leave a comment:
-
I think % (mod) is only used with integers.I think you need to use:Code:fmod(). e.g. cout<<fmod(7.6,2.5)<<endl;//prints 0.1
Leave a comment:
-
Suggest the following:
1)Declare and initialize a 4x4 array with integers 1 to 16.
int arr[4][4]={{1,2,3,4},{5, 6,7,8},etc.}};
2)Print the array with 2 loops similar to those in your code.
//loop_1 using int i.
//loop_2 using int j.
cout<<arr[i][j];//don't forget the '\n' and braces!
3)Use if ...else statements and array indexes in combination with a swap() function (defined in <algorithm>)t o...Leave a comment:
-
Yes...thanks, I've been back over it and what you both have said is what i have been reading. Some things just seem to go through to the keeper without registering.Leave a comment:
-
to Banfa: I agree having tried it that an array won't even work for me presumably because a variable needs a name before memory is allocated and it becomes an object.
But I can't see how a pointer is also a variable because i understood that a valid pointer only ever contains the address of whatever it currently points at (or to). Although this has no bearing on the argument i also thought that a pointer had to be initialized at the time it...Leave a comment:
-
Here's what the inventor says about it:
"The places in which we store data are called objects. To access an object we need a name. A named object is called a variable and has a specific type... the data items we put into variables are called values. The statement that defines a variable is (unsurprisingly ) called a definition"Leave a comment:
-
Put the unsigned integer into the first element of an array and call printf on the array name. Also I don't think I have ever read (or heard)that a pointer could be classified as any form of variable.Leave a comment:
-
In C++ you could do something like this.
prompt: enter given name
cin>>given_name ;
prompt: enter surname
cin>>surname;
cout<<surname<< ", "<<given_name<< endl;Leave a comment:
-
to:weaknessforc ats. yes i am pretty weak on lists so will need to dig a bit. The PO (or is it OP) in this case specified that he/she had two arrays and simply wanted to swap a row in one with a column in the other. but I understand in principle what you are telling me and appreciate it.Leave a comment:
No activity results to display
Show More
Leave a comment: