-
prime numbering
i am trying to make a program that checks if the number is a prime number:
Code:
#include <stdio.h>
int prime( int a )
int main(){
int b;
printf("type in the number:")
scanf("%d",&b);
if (prime( b )==b){printf("of course");}
else {printf("nope=no hope");}
getchar();
return 0;}
int prime( int a ){
int x;
for(x=2;x<a;x++){
if(!(a%x==0)){return a;}}}
but when i run it after typing in the number it quits
pleasse help!!!
-
what your prime function should return if the number is prime and if it is not?
And where is the second return?
-
sorry but it really hard for me to read and consequently understand your code
please see this.
C Coding Standards
Code:
int testprime(int no)
{
int i;
for(i=2;i<no;i++)
{
if((no % i) == 0)
{
return 0;
}
}
return 1;
}
so if 1 is returned then number is prime.