How to check if 3 numbers are a Pythagorean triple? [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 1 year ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Duplicate This question has been answered, is not unique, and doesn’t differentiate itself from another question.
Improve this question
How we could get three numbers without ordering and then check if they form a Pythagorean triple or not?
So, pythagorean(3, 4, 5) or pythagorean(5, 3, 4) will print/return true, while pythagorean(4, 3, 6) will print/return false.

You can use this algotrithm :
#include<stdio.h>
int main(){
long long int a, b, c ;
scanf("%llu %llu %llu", &a, &b, &c);
if (a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)
{
printf("YES");
}
else
printf("NO");
return 0;
}

If you use the equation, a^2 + b^2 = c^2, c should be the largest number and the order of a and b should not matter. Just find the largest number, set that equal to c, and then set the other two values to a and b and check to see if the equality is true.

Related

I am a beginer at programming,I wrote a code which gives perfect output but online judge didn't accepted.Why it's happen?(Codeforces problem 69A. ) [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 1 year ago.
Improve this question
#include<stdio.h>
int main(){
int a,b[101],i,j,sum=0;
scanf("%d",&a);
for(i=0;i<a;i++){
for(j=0;j<3;j++){
scanf("%d",&b[j]);
sum=sum+b[j];
}
}
if(sum==0) printf("YES\n");
else printf("NO\n");
return 0;
}
outputs are showed perfectly but online judge didn't accept.
online judge message"wrong answer on test 81".
link of problem"http://codeforces.com/problemset/problem/69/A"
The problem is asking to check if the sum of all vectors is zero.
Sum of vectors is element-wise addition of vectors, not simple summation of all elements.
Your program will fail in, for example, this case:
1
1 0 -1

Integer Overflows in C and Defenses Against Numeric Errors [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 4 years ago.
Improve this question
I am trying to research various integer overflow scenarios in C and I was wondering does the C language provide any defenses against numeric errors and are there any additional classes or libraries in the C language that can help with that? Also, can anyone give me an example of code that results in an integer overflow in C?
No, there are no defenses.
This overflows:
#include <limits.h>
#include <stdio.h>
const int a = INT_MAX - 2;
const int b = INT_MAX - 2;
printf("%d + %d = %d\n", a, b, a + b);
When I tested it it printed -6, but anything could happen I guess.

Using same integers multiple times in scanf [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
is it possible to use same integers in multiple scanf's? For example, I input int i and j, then give them a value in scanf, and print their sum. Then use another scanf to assign different values to the same integers, and now add THEIR sum..
Do you mean this?
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
Of course it would work. The variable's value simply changes. Its the same if you wrote
int a;
a = 4;
. . .
a = 8

how this code will work for bigger range number? [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 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.

Write c program to find mean of two numbers without using division [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 7 years ago.
Improve this question
I just wonder how to find mean of two numbers without using division.
do not use these conditions :
int mean = (a + b) >> 1;
four fundamental arithmetic operations
I think this may be helpful -->
int a,b,i,j;
if (a>b)
{
int temp = a;
a = b;
b = temp;
}
for(i=a,j=b;i<j;i++,j--)
continue;
if(i==j)printf("%d\n", i);
else printf("%lf\n", (double)(i)-0.5);
Add them then multiply by 0.5 , no division involved.
If they're both integers, you can use a right shift:
int median = (a + b) >> 1;

Resources