C/C++ :: Check Rational Or Irrational Numbers After Taking Square Root?

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


ADVERTISEMENT

C++ :: User Input Two Numbers - Calculate Square Root Then Roots Are Added Up To Return Sum

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

C++ :: Square Root Of Number

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

C :: Program To Find The Square Root Of A Number

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

C :: Prototype Function Square Root Velocity

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

C :: Function Macro For Finding Square Root Of A Number

Jul 13, 2014

How to write a function macro in C for finding the sqrt of a number?

View 2 Replies View Related

C++ :: Newton Method Program For The Square Root Of A Number

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

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

C :: How To Define Epsilon In Newton Raphson Square Root Program

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

C++ :: Work With Fractions And Irrational Numbers

Feb 17, 2013

I'm looking for a library that handles rational, irrational and trascendental numbers and calculates the exact results without approximating values. For example, if I want to calculate:

a = pi;
b = 3;
c = 2;

I want this library to return the result in this way:

sqrt(b*c)*a == sqrt(6)*pi

instead of

sqrt(b*c)*a == 7.6952989

In case it matters, I'm working on Ubuntu and I compile with g++.

I'm pretty sure a library like that exists because it's too useful, I researched it but couldn't find anything.

View 4 Replies View Related

C++ :: Rational Number Class - Handling Numbers Of Different Denominators

Apr 6, 2014

My assignment is to handle rational numbers of different denominators...

Develop rational number class that can
•add
•subtract
•multiply
•divide
•reduce to simplest form
Your class must be able to handle rational numbers of different denominators

This is the errors I am getting

error C4716: 'Rational::addition' : must return a value
error C4716: 'Rational::multiplication' : must return a value
error C4716: 'Rational::division' : must return a value
error C4716: 'Rational::subtraction' : must return a value

View 1 Replies View Related

C++ :: Use Class Structure To Create Program That Reads In Two Rational Numbers?

Nov 4, 2013

how to use a Class structure to create a program that reads in two rational numbers and adds them, subtracts, multiplies, and divides them.

View 3 Replies View Related

C++ :: Display Remainder Of The Square Of Numbers From 100 To 10

Mar 31, 2013

Display the remainder of the square of numbers from 100 to 10. This square of numbers must be divisible by the numbers from 100 to 10 respectively. what i need to in this

View 3 Replies View Related

C++ ::  Calculating Sum Of Square Of Numbers Between Two Inputs

Mar 28, 2014

Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.

This is what I came up with but it is not correct:

#include <iostream>
using namespace std;
void sumsquares(int number1, int number2) {
int sum = 0;
for(int i = number1; i<number2; i++)
sum =sum+ i*i;
cout<<"The Result is: "<<sum<<endl;

[Code] .....

View 2 Replies View Related

C++ :: Printing Square Free Numbers?

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly.

A square-free number is a number that is not evenly divisible by the square of any prime number. It's hard to see the bold in the code area, but it begins after the "//I think below is where the problem is"

#include <iostream>
#include <vector>
using namespace std;

[Code]........

View 1 Replies View Related

C/C++ :: Printing Square Free Numbers

Feb 27, 2014

I'm currently trying to write a program that takes an integer input from the user and displays that number of square-free numbers. I've gotten most of the program to work, but I encounter an error during the noSquare function that causes it to print incorrectly. I have bolded the area where I believe the problem is what I am doing wrong.

The problem with the program is that it prints ALL numbers from 1 to the input number instead of just the square-free.

A square-free number is a number that is not evenly divisible by the square of any prime number ....

#include <iostream>
#include <vector>
using namespace std;
bool noSquare (int num); //Function to determine if the number is square-free
vector<int> getPrimes(int num); //Function to get a vector of all primes below num
bool isPrime (int number); //Function to determine if individual numbers are prime
int main()

[Code]...

By the way, the in the middle of the code was me trying to bold a section, not an actual part of the code. I can't seem to find where to edit my original post.

View 3 Replies View Related

C/C++ :: Make Program To Square Numbers From 1 To 20

Oct 21, 2012

I want to make program to square the numbers from 1 to 20. i have written this program, it's running but not giving the required answer.i think it is giving a garbage value...

void main(void)
{int a;
  int  b;
b=a*a;
for (a=1; a<21; a++)
{printf("%d",b);
printf("the square is%d=b");
}
getche();}

View 2 Replies View Related

C++ :: Print Square Roots Of Numbers With Rows And Columns

Mar 12, 2013

this is what i have so far

#include <iostream>
#include <cmath>
using namespace std;
int main () {
int v;

[Code] ....

im trying to get the program to print this as an example if the user enters 5 (the rounding of the decimal is optional).

1 1.41 1.73 2 2.24
1 1.41 1.73 2
1 1.41 1.73
1 1.41
1

why its not reading my for loop for rows its only doing columns ...

View 4 Replies View Related

C/C++ :: Displaying Filled Square Next To Hollow Square?

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

C/C++ :: Irrational Results In Bounded Pareto Distribution Code

Jan 24, 2015

I wrote the bounded pareto distribution and I add it to simulator but I have irrational results (job sizes between 0.00000-1.1111)

double b_pareto(k,q)
double k; // the K vaue represents a lower limit of job size
double q; // the q vaue represents an upper limit of job size {
double a = 1.5; // alpha value
double rv; // the Returened Value

[Code] ....

View 4 Replies View Related

C++ :: Draw A Square Within A Square Pattern

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

C :: Check Random Numbers To Appear Once Or Twice Only In Each Row Or Column

Oct 25, 2013

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
#define rows 9
#define columns 9

[code]....

View 9 Replies View Related

C :: Check How Many Times Numbers In Array Are Listed

Dec 24, 2013

How can I check how many times the numbers in the array are listed?

View 2 Replies View Related

C++ :: If Else Statement To Check Multiple Model Numbers

May 2, 2013

I need to create a if else statement to check multiple model numbers (200+)... How can i build this? I basically want the user to enter their model number and if its on the list they get a approved or denied message.

So far I have this, the "if(model == 9002||1002)" doesnt seem right, it needs to basically check 200+ model numbers... am I even on the right track?

Code:
#include <iostream>
using namespace std;
int main(){
int model;
cout << "Enter model" << endl;

[Code] .....

View 3 Replies View Related

C++ :: How To Error Check If User Input Is Letters And Not Numbers

Jun 9, 2014

How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.

I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?

Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void OpenTheFile() {
ifstream inputFile;
string filename;
char letter;
int number;

[Code] .....

View 1 Replies View Related

C++ :: Rational Number Using Class

Nov 1, 2013

I complete this program, but the only thing is that it won't execute the program.the other problem is the program is not running as it is suppose to.

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
class Rational

[code]....

View 1 Replies View Related







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