how this code will work for bigger range number? [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
if the range of d is 1<= d <= 10^101 and n is 1<= n <= 200. since the range of double is 2.3E-308 to 1.7E+308. when i take input 11111111111111111111 as d then the value d become 11111111111111111000.000 when i show the value to terminal. that means that it couldn't take the input correctly then how will it give correct value for 10^101. i need know the nth root of d. d will be always in form of p = k^n. that's why i added pow function to know the nth root. but the problem is that the range of p is huge. what i am trying is to solve this problem Power of Cryptography !
int main(){
double d,n;
scanf("%lf%lf", &n, &d))
{
printf("%lf\n", pow(d, 1/n));
}
return 0;
}

A double precision number is not capable of holding all the values between 2.3E-308 to 1.7E+308, it is capable of holding a value between these numbers to a precision of about 15 decimal places.
That means some numbers (such as your example) require more precision than the 8 bytes of data can store.

Related

How to merge multiple numbers into one number like 4,0,0 into 400 without stdlib [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
The community reviewed whether to reopen this question 7 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I'm trying to parse a file that has following data eg:
MAGICNUMBER 400
4 is = 0x34
0 is = 0x30
4
0
0
are different unsigned chars
what i want is those different chars to be converted into
unsigned int x = 400;
when parsing them into my program i want to merge them into one integer i tried bitshifting but it didn't work and i probably did it very wrong and got a very large number probably due misunderstanding of something, what i'm susposed to do to merge those numbers without string tricks and without using std but only using bitshift with a explanation how it works?
Each digit is c - '0'. When you get a new digit, you know that prior ones are one decimal place greater, so you multiply the current number by 10 and add the new digit:
char *s = "400";
int sum = 0;
while(*s >= '0' && *s <= '9') {
sum = 10 * sum + (*s - '0');
s++;
}

How can I run this code without defining x and y in my program? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
So, the question was find the greatest number using "if" statement between three numbers. I wrote the program myself and I'm a newbie to programming so, I tried to run this program but it showed 2 errors repeatedly.
error 1: x is undefined
error 2: y is undefined
So, I understand that it wants me to define the value of x,y but what I want to do is to firstly Compare the value of a and b and then compare the value of c with the greater number I got by comparing a and b.
I'm pasting my code below:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
printf("enter any three number::");
scanf("%d%d%d",&a,&b,&c);
if(x=(a>b)||(b>a));
printf("\n(a>b)||(b>a)=%d",&x);
{
if(y=(x>c)||(c>x));
printf("\n(y>c)||(c>y)=%d",&y);
}
getch();
return 0;
}
How can I improvise this? Hoping for positive response!
The problem is, you never defined x and y, as your compiler pointer out. Just define them like you did for other variables.
int a,b,c,x,y;
would do the job.
That said
you don't really need those if statements, as you used here.
The result of the relational operators (< / >) are not the numbers, it's an integer value, either 0 or 1.
For %d, you don't need to supply the address of the variable, just the variable is enough.

How to find an optimum location point on a line? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
A line is given and a bunch of points are given. I have to find a point on line for which sum of distances from given points is minimum. I could't find any algorithm to implement in c. Please help, thanks in advance.
Without loss of generality, the line is the X axis (otherwise rotate the whole geometry). Then you want to minimize
Sum √[(X - Xk)² + Yk²]
which you can do by canceling the first derivative
Sum (X - Xk)/√[(X - Xk)² + Yk²] = 0
Unfortunately, this is a nonlinear equation that will require numerical methods.
As a starting approximation, you can use the minimizer of the sum of the squared distances,
Sum [(X - Xk)² + Yk²]
by solving
Sum (X - Xk) = 0
which simply gives the point (X*, 0) where X* is the average abscissa.

I need a variable that have a small range value [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have an input number that it's value is not always consistent, i mean the value change plus 1 or minus 1 and etc. So, i want to compare it with a const but have a small range value, for example a const int Dist that have value between 14 to 16. Is that possible to implement it on C programming? Please help me.
You can set constant for lower bound, and constant for upper bound and check if the value falls within the range.
Pseudocode:
int const LOWER_BOUND = 14;
int const UPPER_BOUND = 16;
if (input <= UPPER_BOUND && input >= LOWER_BOUND)
... logic here ...

How to write a C program fulfilling the requirements [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Today I came across a question. It says that:
You need to find if a number can be expressed as sum of two perfect powers. That is, given x find if there exists non negative integers a, b, m, n such that a^m + b^n = x where 1 <= x <= 1000000 and m > 1, n > 1
Could someone please explain me how this can be done?
I know that we can write something like this:
for(int a = 1; true; a++){
for(int b = 1; true; b++){
// And so on and so forth
}
}
But this is not the very efficient (or correct) way of doing so.
Thanks.
Sometimes, that is the only way to solve these kind of problems. The one you have posted belongs to a class of problems called "one way functions": there is a trivial implementation of the problem in one way...
Given four non negative integers, a, b, m and n, find x so a^m + b^n = x
But the other way...
Given x, find four non negative integers a, b, m and n, so a^m + b^n = x
is non trivial. In fact, it could be impossible to solve it, or your best chance, have to use a force brute algorithm to solve it, which is what you have proposed.

Resources