Hi there, I've written a c program in answer to the following question:
write a function prime that returns 1 if its argument is a prime number and 0 if it is otherwise.
My code is:
Code:
// write a program that returns 1 for prime number and 0 if not prime
//source: stephen kochan, programming in C, chapter 8
#include<stdio.h>
// function to check n is prime or not
void prime (int n)
{
int i, c = 0;
for (i = 1; i <= n; i++) {
if (n % i == 0) {
c++;
}
}
if (c == 2) {
printf("1\n");
}
else {
printf("0\n");
}
}
int main (void)
{
void prime (int n);
int m;
printf("Please Give a number to check whether prime or not\n");
scanf("%i", &m);
prime(m);
return 0;
}
The issue is I'm only printing 1 or 0. How am I supposed to RETURN these values from the function? A little confused, any help would be appreciated.