Check my code there is wrong output
Check now.
what is the use of size_t
The datatype size_t is unsigned integral type. It represents the size of any object in bytes and returned by sizeof operator. It is used for array indexing and counting. It can never be negative.
Instead of that, you can also take int.