Is this a joke?
Can you do it for me i can't be bothered?
Valaraukar commented: Good start for a new programmer :) +2
Is this a joke?
Can you do it for me i can't be bothered?
Have you attempted anything?
Sorry if this is repetative but still struggling with this.
i wish to multiply 2 long integers together.
if the result is outside of int64 range i want the loop to break
otherwise i want to keep the result and increment the second number.
have tested this, but when the result is out of range it returns a garbage value.
is there any way of making this result 0 for example when this is the case.
thanks.
when i try to use pow with cmath header i get error message pow(int,int)is ambiguous
it also gives other possible options i.e pow(double,int)
why is int^int ambiguous? how could it be less ambiguous?
not unwilling just not ready yet
been at this 2 months taking one step at a time
using whats there first before thinking about importing more
not avoiding it just learning
That's a stupid reason. If you avoid things you don't know about because you don't know about them, you'll never progress beyond your current ability
thanks for the help i'll figure it out. remember when rebuking someone
"one must learn to walk before one can run."
if i was unwilling to learn new things i wouldn't have got here
:)
ok have tried your code and it works beautifully(will use it from now)
but try my amended code against yours and see if the answer is correct
it takes more calculations but they are just subtractions
dont know if subtractions are quicker or slower than modulus operations(noob)
would be pleased to know if it was luck that gave correct answer or not.
p.s came across the subtraction thing on wikipedia
or
sum+=number
probably just being a bit silly
sorry should have said that i'm very new at this(couple of months)
dont quite understand what you've posted
not willing to use external libraries(given i don't know how to)
how are "ERANGE" and "HUGE_VAL" defined
p.s i agree b will have a limit but it will be dependant on a
so what i meant was that b will have no stated limit in the loop
it will abort when a^b is too big
hi, beginner question
i am planning to write code for different values of a^b.
both a and b will vary in the program and both will be long long ints;
as my compiler wont allow pow(int,int) as it is ambiguous(dont know why)
either while have a as a double and cast it to LL int or just use multiplication
with a as LL int.
Sorry im rambling.
My question is how do i terminate the loop when a^b is
out of LL int range instead of it just returning me a garbage value and carrying on?
In other words b will have no limit will just break when a^b is too large.
sorry about the messy thread and thanks for the help in advance.
p.s has to be int as i'm going to do modular operations on it.
line 9 should read
for(index=0; index < strlen(pointer); index++)
P.S. am just learning to program so this might be wrong
ok small change to this
int g_c_d(int a,int b)
{
int c;
c=abs(b-a);
cout<<a<<" "<<b<<" "<<c<<endl;/*put this in to check it was going ok*/
if(b>a){b=a;}
a=c;
if(c!=0){return g_c_d(a,b);}
return b;
}
seems to give correct answer but just looks wrong to me
ok not got the hang of recursion and will try this but
why is the return value as it is?
trying to write a fuction to work out the GCD of two numbers
seems to run ok but the return is incorrect
any help much appreciated
#include <iostream>
#include <cmath>
using namespace std;
int g_c_d(int a,int b);
int main()
{
cout<<g_c_d(2871,4060);/*test example*/
cout<<endl;
system("pause");/*been advised not to use this but at my level well hey!*/
return 0;
}
int g_c_d(int a,int b)
{
int c;
c=abs(b-a);
cout<<a<<" "<<b<<" "<<c<<endl;/*put this in to check it was going ok*/
if(c==0){return a;}
if(b>a){b=a;}
a=c;
g_c_d(a,b);
}
returns 4249024 instead of 29
sorry this may be double post just new to this
didnt know wether it should be code snippet or discussion thread
Hey there,
this code was supposed to work out th GCD of 2 numbers
added cout line in function and code seems to be running fine
but it returns 4249024 instead of 29
this is probably a basic error on my part but can anyone tell me why?
thanks for any help
as is quite clear am a beginner at this.
#include <iostream>
#include <cmath>
using namespace std;
int g_c_d(int a,int b);
int main()
{
cout<<g_c_d(2871,4060);/*test example*/
cout<<endl;
system("pause");/*been advised not to use this but at my level well hey!*/
return 0;
}
int g_c_d(int a,int b)
{
int c;
c=abs(b-a);
cout<<a<<" "<<b<<" "<<c<<endl;/*put this in to check it was going ok*/
if(c==0){return a;}
if(b>a){b=a;}
a=c;
g_c_d(a,b);
}
thanks guys
next_permutation did the job nicely
now gonna go and find out how it works
feel like i should know how to write my own algorithms
this might slow my learning but hate using something i dont understand
just me being me :)
thanks gonna give that a try
still feel i should know what its doing though
one thing at a time i suppose
thanks for the help but think this is just beyond me at the moment
need to do some more reading i think
was following some of your explanation but go lost
need to learn more about recursion and functions
THANKS FOR THE HELP
not being funny but thats the part of the prblem i knew how to do.
if i have it correct recursion is a function calling itself
have written a factorial program before but just used a while loop
Think the problem here is not telling the computer how to answer my question
the problem is i dont know what the question is
ok figured it out now thanks
Hi, total beginner here, trying to learn at home.
Just thought i'd get that in.
if i have a number eg 123
trying to figure out a way of calculating all the possible cominations
123
132
213
231
312
321
can do it with pencil and paper but don't know where to start with program
can anyone help?
ok but will this all be char
need to work on the numbers mathematically
how to seperate them into individual integers?
planned to put in a 2D array
going to add these numbers together
if i have this wrong please correct me(still beginner) :)
was just copied off web page using ctrl c (project euler problem 13)
not in file
is a list of 100 50digit numbers
165..........567
................
................
765..........423
etc etc
Hey there.
Just beginning to learn c++ on my own(not easy).
Please fogive my lack of knowledge.
I have a list of large numbers(50 digits) that i copied.
I want to split them into an integer array of size [100][50].
I dont want to have to go through and put in all the commas(obviously >4000).
Does anyone have any suggestions for an easier way.
thanks in advance.
That seemed to work(long long).
Program was taking forever and never finished but think that was just my bad programming. Gave first 4 prime factors and apparently fouth was biggest.
Thanks for the help.
Ok, but isn't an unsigned long int only up to 4294967295?
Have to use int i think because am using modulus(%) operator.
As for _int64, have never seen before, could you explain what it is?
Remember am still at very early stage.
Thanks for any help.
Hey there folks. New at this so forgive any mistakes, first post.
I'm beginning to learn c++. Not so easy.
After reading a few threads went to project euler.
Problem i have is problem 3.
"
The prime factors of 13195 are 5,7,13 and 29.
What is the largest prime factor of the number 600851475143 ?
"
Wrote my program and seems to work on the example given(13195) and on larger numbers,
but when i try anything larger than 10 digits nothing happens and program ends.
Does anyone have any suggestions on how to fix this.
Grateful for any help.
Not posted code didn't think it mattered but can if need be.