Problem 6

10 comments on “Problem 6”


  • Shivangi

    import java.util.Scanner;

    public class PythogoreanTriplets {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter the limit: “);
    int n = sc.nextInt();
    double c=0;
    for(int a=1;a<=n;a++){
    for(int b=a+1; b<=n;b++){
    c = Math.sqrt(a * a + b * b);
    if (Math.ceil(c) == c && Math.ceil(c)<=n) {
    System.out.println(a + " " + b + " " + (int) c);
    }
    }
    }
    }
    }


  • kotyada Harish

    import math
    def pythagorean_triplet(n):
    for b in range(n):
    for a in range(1, b):
    c = math.sqrt( a * a + b * b)
    if c % 1 == 0:
    print(a, b, int(c))

    pythagorean_triplet(20)


  • sai

    import java.util.Scanner;
    public class Triplet {
    public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int a, b, c;
    System.out.println(“Enter the value of n: “);
    int n = in.nextInt();
    System.out.println(“Pythagorean Triplet upto ” + n + ” are:\n”);
    for (a = 1; a <= n; a++) {
    for (b = a; b <= n; b++) {
    for (c = 1; c <= n; c++) {
    if (a * a + b * b == c * c) {
    System.out.print(a + ", " + b + ", " + c);
    System.out.println();
    } else
    continue;
    }
    }
    }
    }
    }


  • sai

    import java.util.Scanner;
    public class Triplets {
    public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int a, b, c;
    System.out.println(“Enter the value of n: “);
    int n = in.nextInt();
    System.out.println(“Pythagorean Triplets upto ” + n + ” are:\n”);
    for (a = 1; a <= n; a++) {
    for (b = a; b <= n; b++) {
    for (c = 1; c <= n; c++) {
    if (a * a + b * b == c * c) {
    System.out.print(a + ", " + b + ", " + c);
    System.out.println();
    } else
    continue;
    }
    }
    }
    }
    }


  • Ravisankar ka

    import java.util.Scanner;
    public class Triplets {
    public static void main(String args[]) {
    Scanner in = new Scanner(System.in);
    int a, b, c;
    System.out.println(“Enter the value of n: “);
    int n = in.nextInt();
    System.out.println(“Pythagorean Triplets upto ” + n + ” are:\n”);
    for (a = 1; a <= n; a++) {
    for (b = a; b <= n; b++) {
    for (c = 1; c <= n; c++) {
    if (a * a + b * b == c * c) {
    System.out.print(a + ", " + b + ", " + c);
    System.out.println();
    }

    else
    continue;
    }
    }
    }
    }
    }


  • pratik N

    limit=int(input(“Enter upper limit:”))
    c=0
    m=2
    while(c limit):
    break
    if(a==0 or b==0 or c==0):
    break
    print(a,b,c)
    m=m+1


  • pratik N

    limit=int(input(“Enter upper limit:”))
    c=0
    m=2
    while(climit):
    break
    if(a==0 or b==0 or c==0):
    break
    print(a,b,c)
    m=m+1