[x]Register Now
Check out our brand new Local Poker Communities! Get updates and interact with poker players in your area.
Visit the United States Poker Community | Visit the California Poker Community | Read more about the Launch of P5s Local
Visit the United States Poker Community | Visit the California Poker Community | Read more about the Launch of P5s Local
-
I'm taking a C++ class and am having trouble with a couple of the questions. I'm offering $10 on stars or Full Tilt if someone can write a program for these problems. They shouldn't be too hard if you know what you're doing, unfortunately, I don't.
1. The greatest common divisor of two integers a and b, GCD (a,b) not both of which are zero, is the largest positive integer that divides both a and b. The Euclidean algorithm for finding this greatest common divisor of a and b is as follows:
* Divide a by b to obtain the integer quotient q and remainder r so that a = bq + r. Note: if b=0, then GCD(a,b) = a.
* Now, GCD(a,b) = GCD(b,r) so replace a with b and b with r, and repeat this procedure.
Since the reaminders are decreasing, eventually a remainder of 0 will result. The last nonzero reminder is GCD(a,b). For example,
1260 = 198 x 6 + 72 GCD(1260,198) = GCD(198,72)
198 = 72 x 2 + 54 = GCD(72,54)
72 = 54 x 1 + 18 = GCD(54,18)
54 = 18 x 3 + 0 = 18
Write a program that reads two integers and then calls a function named gcd that calculates and returns the greatest common divisor. Display the two integers and the greatest common divisor on the terminal screen.
Note: If either a or b is negative, replace it with its absolute value.
2. Often computers are used to explore data arising from functions. Suppose you want to explore the behavior of the function
f(x,y,z) = 1.2sin(pi * x) * cos(pi * y / 4) * (2.1 - (2.0 - z)^2)
Specifically, supose you want to evaluate this function over the 3D block x,y,z E [1.0,3.0] with the function evaluated at increments of 0.2 in all three directions. That is, the function should be evaluated at all points (x,y,z) where x,y,z E {1.0, 1.2, 1.4, .... 3.0}.
Write the function f as a C++ function, and write a main program that asks a user to input a range minimum and maximum a and b, evaluates f at the data sites, and counts and outputs the number of sites at which the return value of f(x,y,z) is in a range [a,b]. -
Hmm, think I've made something similar to this, I'll look for it and get back to you.
-
are there other people in your class? I got an A+ in this course using 2 simple commands
ctrl+c
Ctrl+v -
1. Ok, forgive me as I haven't done any of this in forever, but I believe this while function should get your divisor. Of course you have to get the input and keep it store it in order to output both a and b later. Add an if(a<0){a=a*(-1);) and the same for b before the while loop to get rid of the negatives.
all variables are ints, get a and b from input, and define r as nonzero before the while loop
while(r!=0){
q=a/b;
r=a-b*q;
if(r!=0){
a=b;
b=r;
}
}
If this is retarded, please forgive me as I haven't done any of it in years, and never did much in depth anyway. -
the answer is 4
-
2.
I think this should work. Anyway, you can get the basic idea.
#include <stdio.h>
$include <iostream.h>
#include <math.h>
int main()
{
int count = 0;
cout << "Enter value for a: ";
cin >> a;
cout << "Enter value for b: ";
cin >> b;
for (double x = 1.0; x <= 3.0; x = x + 0.2)
{
for (double y = 1.0; y <= 3.0; y = y + 0.2)
{
for (double z = 1.0; z <= 3.0; z = z +0.2)
{
f = 1.2 * sin(3.1416*x)*cos(3.1416*y/4)*(2.1-(2.0-z)^2);
if (f >= a && f <= b)
{
count++;
printf("x: %f y: %f z: %f f: %f ", x, y, z, f);
}
}
}
}
cout << "Number of sites: " << count;
return 0;
} -
lol if you can't do this c++ problem; i feel sorry for you the rest of the semester; and college for that matter.
-
1.
int gcd(int a, int b) {
int r = a%b;
if(r == 0) return b;
return gcd(b, r);
}
2.
void function() {
const double PI = 3.14159;
int count = 0;
cout << "Enter value for a: ";
cin >> a;
cout << "Enter value for b: ";
cin >> b;
for(double x = 1.0; x <= 3.0; x+=.2) {
for(double y = 1.0; y <= 3.0; y+=.2) {
for(double z = 1.0; z < = 3.0; z+=.2) {
double f = 1.2 * sin(PI * x) * cos(PI * y / 4) * (2.1 - ((2.0 - z) * (2.0 - z)));
if(f >= a && f <= b) count ++;
}
}
}
cout << "Number of sites: " << count << endl;
return;
}
this should be right. didn't bother putting it into a compiler to see if it worked. if you need an explanation on how this stuff works PM me -
recursion rocks.
-
showboatin imo.
jk brian!! how does it feel to be back at work? -
sucks, i'm blind and my eye hurts from looking at the screen all day.
i won't hijack this thread though, you can talk to me on AIM. -
im at school -no aim... ttyl mang
Similar Threads
- 21 Replies
- 0 Replies
- 2 Replies
-
1 Replies
full tilt problem please help
By fulltiltbabe in Poker Discussion
Last Post: Mar 11th, 2007, 10:40 AM - 3 Replies











