11854 why WA??

Write here if you have problems with your C++ source code

Moderator: Board moderators

11854 why WA??

Postby cse.mehedi » Fri Apr 13, 2012 9:33 pm

Help me any one!!! :(
Code: Select all
#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;
int main()
{
    long a,b,c;
    while(1)
    {
        cin>>a>>b>>c;
        if(a==0 && b==0 && c==0) break;
        if( (pow(a,2)+pow(b,2))==pow(c,2))
        printf("right\n");
        else printf("wrong\n");
    }
    return 0;
}

cse.mehedi
New poster
 
Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

Re: 11854 why WA??

Postby brianfry713 » Tue Apr 17, 2012 1:13 am

Don't use pow to square an integer, pow returns a double and could lead to precision errors. You are assuming that the inputs are given in order a, b, c, which is not in the problem statement.
brianfry713
Guru
 
Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to C++

Who is online

Users browsing this forum: No registered users and 1 guest