Where do we need to write the input statement?

if we are making function to find something then is it must that we always have to write the input statement in int main() function. can we also write input statements in function body? here in this program the input statement is written in int main function body. can we declare variables to get input in outside the int main body?

Yes you can take input anywhere you want.