bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / APC-PRAC-039.c

APC-PRAC-039.c (940B)


      1 /*
      2 Write a C program to print all unique combinations of three numbers (a, b, c) such that:
      3 1 ≤ a, b, c ≤ 30 and a² + b² = c² (Pythagorean triplets)
      4 */
      5 /* Author: Amit Dutta, Date: 21-11-2025 */
      6 
      7 // This code has not been compiled.
      8 // If you find any issues, please create a new issue on GitHub regarding them.
      9 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues
     10 
     11 #include <stdio.h>
     12 
     13 int main()
     14 {
     15     printf("a² + b² = c² :  ");
     16     int i, j, k, sq1, sq2, count = 0;
     17     for (i = 1; i <= 30; i++)
     18     {
     19         sq1 = i * i;
     20         for (j = i + 1; j <= 30; j++)
     21         {
     22             sq2 = j * j;
     23             for (k = j + 1; k <= 30; k++)
     24             {
     25                 if (sq1 + sq2 == k * k)
     26                 {
     27                     printf("(%d, %d, %d)  ", i, j, k);
     28                     count++;
     29                 }
     30             }
     31         }
     32     }
     33     printf("\n\nCount: %d\n", count);
     34     return 0;
     35 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror