Problem 6

26 comments on “Problem 6”


  • rohan

    #include
    int main()
    { int n,i,j,k,m;
    printf(“enter the max number for pyto triplet “);
    scanf(“%d”,&n);
    m=n+1;
    for(i=2;i<=n;i++)
    {
    for(j=2;j<=n;j++)
    {
    if(j==m)
    {
    continue;
    }
    for(k=2;k<=n;k++)
    {
    if(i*i==j*j+k*k)
    {
    printf("%d %d %d \n",i,j,k);
    m=k;
    }
    }
    }

    }

    return 0;
    }


  • The Bong

    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();
    }
    }
    }

    }
    }


  • Febin

    n=int(input(“Enter the limit”))
    for i in range(1,n+1):
    for j in range(1,i):
    for k in range(1,n+1):
    a=i*i
    b=j*j
    c=k*k
    if((a+b)==c):
    print(j,i,k)


  • 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