Types of User-Defined Functions in C Programming
Types of User-Defined Functions in C Programming
com
5-6 minutes
The output of all these programs below is the same, and we have
created a user-defined function in each example. However, the
approach we have taken in each example is different.
#include <stdio.h>
void checkPrimeNumber();
int main()
{
checkPrimeNumber(); // argument is not
passed
return 0;
}
#include <stdio.h>
int getInteger();
int main()
{
int n, i, flag = 0;
// no argument is passed
n = getInteger();
if (flag == 1)
printf("%d is not a prime number.", n);
else
printf("%d is a prime number.", n);
return 0;
}
return n;
}
Here, the getInteger() function takes input from the user and
returns it. The code to check whether a number is prime or not is
inside the main() function.
#include <stdio.h>
void checkPrimeAndDisplay(int n);
int main()
{
int n;
return 0;
}
#include <stdio.h>
int checkPrimeNumber(int n);
int main()
{
int n, flag;
printf("Enter a positive integer: ");
scanf("%d",&n);
if(flag == 1)
printf("%d is not a prime number",n);
else
printf("%d is a prime number",n);
return 0;
}
return 0;
}