#include <stdio.h>
#include <math.h>
main()
{
int n;
int k;
int j;
//gets user input for length of string
printf("Enter the value of n:");
scanf("%d", &n);
//stores user input as n
printf("Printin g primes less than or equal to %d: \n", n);
for(k = 2; k <= n; k++)
{
if(is_Prime(k) == 1)
{
printf("%d,", k);
}
}
//here is the is_Prime function
int is_Prime (int k)
for(j = 2; j < k; j++)
{
if(k%j != 0)
{
return 1;
}
else(k%j == 0)
{
return 0;
break;
}
}
When I compile my code I get an error saying that I need declaration specifiers in my is_prime subroutine in the for loop. Can anyone explain what this means or how to fix it? Here is the line of code it references.
for(j = 2; j < k; j++)
#include <math.h>
main()
{
int n;
int k;
int j;
//gets user input for length of string
printf("Enter the value of n:");
scanf("%d", &n);
//stores user input as n
printf("Printin g primes less than or equal to %d: \n", n);
for(k = 2; k <= n; k++)
{
if(is_Prime(k) == 1)
{
printf("%d,", k);
}
}
//here is the is_Prime function
int is_Prime (int k)
for(j = 2; j < k; j++)
{
if(k%j != 0)
{
return 1;
}
else(k%j == 0)
{
return 0;
break;
}
}
When I compile my code I get an error saying that I need declaration specifiers in my is_prime subroutine in the for loop. Can anyone explain what this means or how to fix it? Here is the line of code it references.
for(j = 2; j < k; j++)
Comment