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++..
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;
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.
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: ");
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);
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); }
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?
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.
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
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
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;
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;
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.
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();}
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.
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
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;
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;