Hello,
I'm very new to programming and I am working on a program to test to see if a random number is prime. This is what I have so far. I'm really stuggling with the logic of it. I understand what I have up to the while loop. I'm pretty sure my while loop is incorrect but I'm not sure how to go about fixing it. Any help would be greatly appreciated. Thanks.
the instructions for the program are:
1.) assign variable isPrime the value true
2.) get input from user and assign to variable oneNumber
3.) assign value of 2 to variable count
4.) while count is less than or equal to (they left it blank here. I assumed it is comparing to oneNumber) and isPrime is true do
if oneNumber can be divided by count then
assign isPrime the value false
else
increase count by 1
5.) output the test result
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
/*Declaring variables*/
int isPrime = 1;
int oneNumber;
int count = 2;
/*Getting input from the user*/
printf("Enter a number greater than 2: \n");
scanf("%d",&oneNumber);
while (count <= oneNumber && isPrime == 1)
if (oneNumber % count == 0)
{
isPrime = 0;
}
else
{
count = count + 1;
}
return 0;
}