Program 61 #P61 - C Program Prime Number Program with Argument passed and a return value #C180
The input from the user is passed to checkPrimeNumber() function.
The checkPrimeNumber() function checks whether the passed argument is prime or not. If the passed argument is a prime number, the function returns 0. If the passed argument is a non-prime number, the function returns 1. The return value is assigned to the flag variable.
Depending on whether flag is 0 or 1, appropriate message is printed from the main() function.
Which approach is better?
Well, it depends on the problem you are trying to solve. In this case, passing argument and returning a value from the function (example 4) is better.
A function should perform a specific task. The checkPrimeNumber() function doesn't take input from the user nor it displays the appropriate message. It only checks whether a number is prime or not, which makes code your code easy to understand and debug.
#rubalsolutions #coding #developer #programming #programmer #technology #clanguage #computerscience #c #informaticpractices #sub #subscribe #youtube #newyoutuber #youtubechannel