I've been writing a program to find prime numbers and it's finding some

wacky errors with my integer declarations or something. I'd give more

info but I don't know what else to say. The error messages and code are

both below

#include <stdio.h>

int sprime(int);

int fprime(int,int []);

int main()

{

/* Ask which prime */

printf("What slow prime?");

int i;

scanf("%d",&i);

/*Initialize speed table for fprime()*/

int table[100];

for(int x=0;x<100;x++)

{

table[x]=0;

}

/*Calculate slowprime and print it out*/

int d;

d=sprime(i);

printf("The %d prime is %d\n",i,d);

/*Ask about fastprime*/

printf("Which fastprime?");

scanf("%d",&i);

/*calculate fastprime and print it out*/

d=fprime(i,table);

printf("The %d prime is %d\n",i,d);

/*we're done*/

return 0;

Quote:

}

int sprime(int n)

{

/*the first prime is 2*/

if(n==1)return 2;

/*It's larger than the previous prime*/

int guess=prime(n-1)+1;

/* We just try division*/

for(int x=2;x<n;x++)

{

if(float(guess)%float(x)==0)

{

x=1;/*We want x to be two, the loop will increment*/

guess++;

}

}

Quote:

}

int fprime(int n,int table[])

{

/*The first prime is 2*/

if(n==1)return 2;

/*The table here maxes out at 99*/

if(n>99)return -1;

/*Did we already find it?*/

if(table[n]!=0)return table[n];

/*We know it's larger than the previous prime*/

int guess=prime(n-1)+1;

for(int x=1;x<n;x++)

{

if(float(guess)%float(prime(x,table[]))==0)

{

x=0;

guess++;

}

}

table[n]=guess;

return table[n];

Quote:

}

prime.c: In function `main':

prime.c:10: parse error before `int'

prime.c:11: `i' undeclared (first use in this function)

prime.c:11: (Each undeclared identifier is reported only once

prime.c:11: for each function it appears in.)

prime.c:13: parse error before `int'

prime.c:14: parse error before `int'

prime.c:14: `x' undeclared (first use in this function)

prime.c:14: parse error before `)'

prime.c: At top level:

prime.c:20: `i' undeclared here (not in a function)

prime.c:20: initializer element is not constant

prime.c:20: warning: data definition has no type or storage class

prime.c:21: parse error before string constant

prime.c:21: warning: data definition has no type or storage class

prime.c:23: parse error before string constant

prime.c:23: warning: data definition has no type or storage class

prime.c:24: parse error before string constant

prime.c:24: warning: data definition has no type or storage class

prime.c:26: redefinition of `d'

prime.c:20: `d' previously defined here

prime.c:26: `i' undeclared here (not in a function)

prime.c:26: `table' undeclared here (not in a function)

prime.c:26: initializer element is not constant

prime.c:26: warning: data definition has no type or storage class

prime.c:27: parse error before string constant

prime.c:27: warning: data definition has no type or storage class

prime.c: In function `sprime':

prime.c:37: parse error before `int'

prime.c:39: parse error before `int'

prime.c:39: `x' undeclared (first use in this function)

prime.c:39: parse error before `)'

prime.c:44: `guess' undeclared (first use in this function)

prime.c: At top level:

prime.c:46: parse error before `}'

prime.c: In function `fprime':

prime.c:58: parse error before `int'

prime.c:59: parse error before `int'

prime.c:59: `x' undeclared (first use in this function)

prime.c:59: parse error before `)'

prime.c:64: `guess' undeclared (first use in this function)

prime.c: At top level:

prime.c:66: parse error before `}'

prime.c:67: `n' undeclared here (not in a function)

prime.c:67: variable `table' has initializer but incomplete type

prime.c:67: `guess' undeclared here (not in a function)

prime.c:67: warning: data definition has no type or storage class

prime.c:68: parse error before `return'

Exit 1

This is getting urgent, please help!!!

Sent via Deja.com http://www.*-*-*.com/

Share what you know. Learn what you don't.