Skip to content

Commit c0db551

Browse files
authored
Create 38_codechef_fits_square_in_triangle.cpp
1 parent 151e26f commit c0db551

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// main.cpp
3+
// CODECHEF
4+
//
5+
// Created by Prince Kumar on 14/05/19.
6+
// Copyright © 2019 Prince Kumar. All rights reserved.
7+
// --- ** Fits square in the triangle ** ---
8+
9+
#include <iostream>
10+
using namespace std;
11+
int main()
12+
{
13+
int T; cin>>T;
14+
while(T--)
15+
{
16+
int b; cin>>b;
17+
if(b==1 || b==2 ||b==3)
18+
cout<<"0"<<endl;
19+
else
20+
{
21+
if(b%2==0) // for EVEN
22+
{
23+
int area = 0.5 * b *b;
24+
int res = (area - b )/4;
25+
cout<<res<<endl;
26+
}
27+
else // for ODD
28+
{
29+
b=b-1;
30+
int area = 0.5 * b *b;
31+
int res = (area - b )/4;
32+
cout<<res<<endl;
33+
}
34+
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)