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

Adding a tutorial for dimik-square-number #490

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
26 changes: 26 additions & 0 deletions dimik-square-number/en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dimik - Square Number

In this problem, you will be given `T` testcases. Each line of the testcase consists of an integer `n`. We just have to identify if the value of `n` is a square number or not.

### Solution
We can find the solution by square rooting the value of `n` using `sqrt` function and multiply against itself through the use of `floor` function. Because the value returned by `sqrt` function is `double` and to compare with the `integer` value of `n`, the datatype `double` is converted to `int` using `floor` function.

### C++
```cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for (int k = 1; k <= t; k++)
{
int n;
cin >> n;
if (floor(sqrt(n)) * floor(sqrt(n)) == n)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
```