Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #28

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Question 3/Answer/Q3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**

Name: Kumar Ashwin
Email: krashwin00@gmail.com
Date: 2nd April, 2020
Version: v1
Problem Statement: There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.

**/

#include<stdio.h>
#include<math.h>
int main()
{
int m=2,n;
int a,b,c,sum,pro;
while(a<333) //as a being the smallest number it must not exceed 333
{
for(int n=1;n<m;n++)
{
//Using Euclid's formulae to find out the triplets (a,b,c)
a=pow(m,2)-pow(n,2);
b=2*m*n;
c=pow(m,2)+pow(n,2);

//finding if the sum of triplets are a multiple of 1000, then we can multiply each digit of triplet to find the numbers when added form 1000.
sum=a+b+c;
if(1000%sum==0)
{
sum=1000/sum;
pro=(a*sum)*(b*sum)*(c*sum);
}
}
m++;
}
printf("abc=%d",pro);
return 0;
}
19 changes: 19 additions & 0 deletions Question 3/Answer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Question 3 - Solution

### Execution Instructions
* **Compiler Details** : gcc
* Type down the command in the linux terminal ` gcc Q3.c -lm -o run `
* The above mentioned command will generate an object file which can be run directly on the terminal using ` ./run `
* `-lm` switch is used to incorporate _math.h_ header file and `-o` switch is used to create an object for the C file.


### Input & Output

* **No Input Required**
* **Output**
> abc=31875000

### Author
* **Kumar Ashwin**
* **Email:** krashwin00@gmail.com