Thread: Hello new to to the forum and also to programmig.

1. Originally Posted by stahta01
Write code to find out if a number is prime.
Until you can do that you do not have a chance at doing this assignment.
After writing a function to determine if a number is prime; than take this code and create a new function (possibly called factor) to do this assignment.

Tim S.

Here is a code to see if a number is prime

Code:
```#include <stdio.h>

int main() {

int N, a, b;

printf("What number do you want to test?\n");
scanf("%d",&N);

for(a=2; a<N; a++) {
if(N % a == 0) {
printf("%d is divisble by %d.\n", N, a);
break;
}
}

if(a == N) //the loop ran completely and never 'broke'
printf("%d is a prime!\n",N);

return 0;```

2. Take you have not yet learned to write functions.
Is this correct?

Tim S.

3. I did a untested change to your code; you might be able to figure out what else to change.

Code:
```#include <stdio.h>

int main() {

int N, a, b=1;

printf("What number do you want to test?\n");
scanf("%d",&N);

for(a=2; a<N; a++) {
if(N % a == 0) {
b = N/a;
printf("%d is divisble by %d.\n", N, a);
printf("%d is divisble by %d.\n", N, b);
}
}

if(b == 1)
printf("%d is a prime!\n",N);

return 0;
}```