C++ :: How To Find The Square Root For Numerator And Denominator Separately
Apr 1, 2014
I having trouble with the rational class
here is my assignment:
Add a square root function to the rational class. Have your program print the square root of any rational number. I want to find the square root for numerator and denominator separatetly. divide the answer to get decimals and convert the decimal to fractions. i got till geting the decimal but i want to convert it back to a simplified fraction
// finding greatest common factor
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}
[Code]...
View 2 Replies
ADVERTISEMENT
Dec 5, 2013
I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..
EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.
It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...
"The square root of 100 is -1077834936"
My first time writing a program from complete scratch.
And I know there is a sqrt() function...just wanted to write my own.
Code:
#include <stdio.h>
#include <math.h>
double mysqrt(double a);
int main()
{
double a, result;
printf("Enter a number to find the square root of: ");
[Code]...
View 1 Replies
View Related
Dec 9, 2013
i have written a function that gives me the square root of a number. Yes i know there is already a function in <cmath> that gives square roots but i thought it would be pretty challenging (and therefore fun) to try writing one on my own. I wrote my code while i was in school, listening to my Irish teacher ramble on and on about useless shit, so it's probably not the best possible way of finding the square root of a number.
double msqrt(double x) {
double adder=1;
double y = x;
for(int a=0; ; a++) {
if(y*y > x) y = y/2;
if(y*y <= x) break;
[code]....
View 6 Replies
View Related
Mar 30, 2013
I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.
#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);
[Code] ....
View 2 Replies
View Related
Jul 13, 2014
How to write a function macro in C for finding the sqrt of a number?
View 2 Replies
View Related
Mar 1, 2013
I have been trying to write a Newton's Method program for the square root of a number and have been failing miserably...
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y;
double x0;
[Code] .....
View 6 Replies
View Related
Mar 6, 2015
I'm working on a c program that generates approximations of square roots based on newton raphson method. I worked out the approximations with another method I learnt and I know this program does fine. But I don't get the concept of epsilon. Below is the code for the program
Code:
#include<stdio.h>
// function to compute absolute value
float absoluteValue(float x)
{
if(x < 0)
x = -x;
[code]....
The text I worked this code from uses the epsilon value arbitrarily. how is the epsilon value selected? I tried using this formula to derive the square root of 45. On paper I can go as far as 6.8 something. But once this value is reached it's still bigger than epsilon, so shouldn't the code keep running? The program generates 1.41 for 2, but since it could go further why does the while loop in squareRoot function terminate?
View 2 Replies
View Related
Aug 4, 2014
I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
View 10 Replies
View Related
Aug 23, 2014
I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.
#include<iostream>
#include<cmath>
float main(){
using namespace std;
float m1,m2,m3,m4,m5;
[Code] ....
View 4 Replies
View Related
Mar 24, 2013
I want to find transpos of square matrix.but my program does not run complete.
Code:
#include<iostream>
using namespace std;
const int size=3;
void read(int a[size][size])
[Code] .....
View 2 Replies
View Related
Apr 1, 2013
Area of the room. Your task is to write a program that will find the area of room in a given square maze.
Note. Use recursion for solving this problem.
Input:
First line contains only one number N (3 <= N <= 10).The number that describes the size of the square maze.
On the next N lines maze itself is inputed ('.' - empty cell,'*' - wall).
And the last line contains two numbers - the row and column of the cell in the room those area you need to find.It is guaranteed that given cell is empty and that the maze is surrounded by walls on all sides.
Output:
Output only one number - total amount of empty cells in the selected room.
View 8 Replies
View Related
Feb 1, 2013
write a C++ program to find the area of a square, input the length of the side, and output your answer to the screen.
View 3 Replies
View Related
Dec 21, 2012
To calculate line slope I am using formula ,
line_slope = (meanxy - (meanx * meany)) / (meanyy) - (meany * meany));
All the variables are floats.
How to check whether the denominator .. (meanyy)- (meany * meany)) is zero ? Cause its float.
can I check with ..
float f1 = (meanyy) - (meany * meany) ;
if (f1 == 0.0) ..
Will this work surely ? I am using this formula in project based on winXP but it survived. As soon as I ported the code on DPMI based code , I observed a system hang after some time if all the points I supply are (0,0) while drawing a line.
View 3 Replies
View Related
Feb 28, 2015
I am able to display a filled and hollow square by themselves, but I can't seem to be able to get them side by side.
So this is my code so far:
[/
#include <iostream>
using namespace std;
int main()
[Code]....
I can get the hollow square to show up, but the first square just shows up as a single line instead of a square. It seems that it ignores the first if statement in the second loop. I've tried not using an if statement in the second loop but it didn't seem to work either.
View 4 Replies
View Related
Oct 25, 2013
I know how to draw a square hollow or filled but i need to draw an alternating pattern ....
ex
iPatternHeight = 1
X
iPatternHeight = 3
OOO
OXO
OOO
[Code] .....
View 6 Replies
View Related
May 25, 2014
I have to prepare a project. But I don t know how can I do this. Program will find a matrix P for a square matrix A such that P^-1 A P ....
View 15 Replies
View Related
Nov 1, 2013
I am trying to write a program that prints a 2d array to the screen and then compares each row and column to see if there is any pairs of letters. basically something that looks like this:
---------------------------
V T A Y U C B
D F W Q Q C R
D A L Y M F G
O A S S D T I
Number of horizontal pairs: 2
Number of vertical pairs: 3
---------------------------
so far this is my code below, but i dont know how to approach the comparisons
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main( void )
[code]....
View 9 Replies
View Related
Mar 4, 2014
How do I enter the equation all at once instead of prompting for each piece separately?
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
[Code].....
View 4 Replies
View Related
Apr 11, 2014
There is any method to compile a method of a class separately from the other methods and the main.
View 1 Replies
View Related
Feb 25, 2015
How can i count total number of each topic separately? For example total number of topic 1 between all nodes. To begin enter 10 and 7 to initial node number and number of topic.
#include <iostream>
#include <vector>
#include <list>
#include <stdlib.h>
#include<time.h>
#include<iomanip>
#include <iostream>
#include <string>
[Code] ....
View 1 Replies
View Related
Oct 25, 2013
I know how to draw a square hollow or filled but I need to draw an alternating pattern
ex
iPatternHeight = 1
X
iPatternHeight = 3
OOO
OXO
OOO
[Code] ......
View 2 Replies
View Related
Oct 4, 2013
I am programming an application in c# that allows the user to edit images. The user can use a Pen to write on the image, and the user can also use a highlighter (a big semi-transparent Pen) to highlight what they've written. I need the user to be able to erase only the highlighting without erasing the pen drawings.
My solution was to have the user draw on one graphics window when the pen is selected and draw on the other graphics window when the highlighter is selected. I will then enable the eraser on either graphics window depending on what the user wants to erase.
My program will let the user save the image and then load it into the program again for later editing. When I save the image, I have to compress the layers (different graphics windows) into one bitmap. When I load the bitmap back into my application, I lose my layers and cannot erase just the highlighting without also erasing the pen as well.
How can I save an image file with layers, and then recover the layers when my program starts up again?
I am not opposed to saving two images - one with the pen graphics window and the other with the highlighting. If I do that, how can I merge the two images into one layer when I load the images back into my program?
View 2 Replies
View Related
Dec 13, 2014
I am having some difficulties splaying this element to the root.. Considering i have this splay tree .
0
1
2
3
4
What are the steps to get it 4 to the root?
View 1 Replies
View Related
Apr 30, 2014
Any way to travel from a leaf to the root. For example I search the tree to find the leaf i want and then trace/record the path back to the root.
View 2 Replies
View Related
Mar 18, 2014
Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.
I.E (this is just an example, they are not inserted correctly)
cat
/
dog buffalo
/ /
fish mouse zebra snake
I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.
void BST::copygreater(node * root, node *& dest, int & holder) {
if(!root) {
dest = NULL;
return;
}
holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?
[Code] ......
View 2 Replies
View Related
May 19, 2013
I got problem in binary tree code. below is my code. When i select pre, post or inorder, the .exe is not responding.. Since in my binary tree theres no roots yet.. who do i solve it? It need condition or what?
View 1 Replies
View Related