Function with no arguments & no return value

Input:

#include <stdio.h>

void checkPrimeNumber();

int main()

{

checkPrimeNumber();    // argument is not passed

return 0;

}

void checkPrimeNumber()   // return type is void means it doesn't return any value

{

int n, i, flag = 0;

printf("Enter a positive integer: ");

scanf("%d",&n);

for(i=2; i <= n/2; ++i)

{

if(n%i == 0)

{

flag = 1;

}

}

if (flag == 1)

printf("%d is not a prime number.", n);

else

printf("%d is a prime number.", n);

}

Output:

Enter a positive integer: 4

4 is not a prime number
-----------------------------------------------------------------------------------
Enter a positive integer: 5

5 is a prime number

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The checkPrimeNumber() function takes input from the user, checks whether it is a prime number or not, and displays it on the screen.

The empty parentheses in checkPrimeNumber(); statement inside the main() function indicates that no argument is passed to the function.

The return type of the function is void. Hence, no value is returned from the function.

HOME/BACK

Comments

Popular posts from this blog

Keywords in C Programming

Definition of C Language

Data Types in C Programming