Problem 6

17 comments on “Problem 6”


  • Sandeep

    import java.util.HashSet; public class PythrogorousTriplets {
    public static void main(String[] args) {
    printTriplets(20);
    }
    static void printTriplets(int limit) {
    HashSet hashSet = new HashSet();
    for (int i = 1; i <= limit; i++) {
    hashSet.add(i*i);
    }
    for (int i = 1; i <= limit; i++) {
    for (int j = 1; j <= limit; j++) {
    int val = (i*i)+(j*j);
    if(hashSet.contains(val)) {
    System.out.print(i+" "+j+" "+" "+(int)(Math.sqrt((int)val)));
    System.out.println();
    }
    }
    } }
    }


  • GAURAV

    #include
    #include
    #include
    using namespace std;

    int main()
    {
    mapmp;
    for(int i=1;i<=20;i++)
    mp[i*i]=1;
    for(int i=1;i<mp.size();i++){
    for(int j=i+1;j<mp.size();j++){
    if(mp.find(i*i+j*j)!=mp.end()){
    int k=sqrt(i*i+j*j);
    cout<<i<<" "<<j<<" "<<k<<endl;}
    }}

    return 0;
    }


  • Raman

    // Online C compiler to run C program online
    #include

    int main() {
    int m=1,n=1;
    int a,b,c;
    for(n=1;n<=20;n++){
    for(m=1;m<=20;m++){
    a=(m*m)-(n*n);
    b=2*m*n;
    c=(m*m)+(n*n);
    if(c0){
    printf(“%d %d %d”,a,b,c);
    printf(“\n”);
    }
    }
    }

    return 0;
    }


  • Raman

    // Online C compiler to run C program online
    #include

    int main() {
    int m=1,n=1;
    int a,b,c;
    for(n=1;n<=20;n++){
    for(m=1;m<=20;m++){
    a=(m*m)-(n*n);
    b=2*m*n;
    c=(m*m)+(n*n);
    if(c0){
    printf(“%d %d %d”,a,b,c);
    printf(“\n”);
    }
    }
    }

    return 0;
    }