I am having problems making this script below work. I want this script to check the numbers input from file imput.txt and tell me if they are Prime or Perfect. (example numbers would be 110, 7, 10, 6 etc. New to C and trying to learn it by doing these types of excersizes. Can someone tell me what I am doing wrong?

Thanks in advance,

Jennifer SEE SCRIPT BELOW:)

# include <stdio.h>

# include <math.h>

int main ()

{

FILE *inp;

FILE *outp;

int num, total, i;

float ans;

int IsPrim;

//Initialize

num = 0;

do

{

inp=fopen("C:input.txt", "r");

outp=fopen("C:output.txt", "w");

fscanf(inp, "%d", num);

printf(outp, "%d", num);

/* printf("\nEnter a number from 1 to 1000>");

scanf("%d", num); */

}

while (num<=0 || num>=1001);

//Initialize

total = 0;

ans = 0;

// For prime

ans = 1;

IsPrim = 1;

for(i = 2; i < num; i++);

if ( num % i == 0)

{

IsPrim=0;

printf("Divisor of prime");

}

if(IsPrim)

printf("It is Prim");

// For perfect

total = 0;

for ( i = 1; i < num; i++)

if(num%i==0)

total+=i;

if(total==num)

{

printf("Perfect");

for ( i = 1; i < num; i++)

if(num%i==0)

printf("Perfect divisor");

}

fclosef (inp);

fclosef (outp);

return (0);

}

main(){

1. open files

2. Do{

read a number

if number >=1 and <=1000

check_if_prime(number);

if (prime)

print "prime"

else

print "not prime"

}while(!eof)

explanation :

1. first of all your conditon was wrong

>>>>> while (num<=0 || >=1001)

so only numbers <= 0 or numbers >= 1001 will satisfy the above condition . i.e numbers like -1 ,-2 or 10987867867868 :)

also you dont need the condition in the while loop as in that case , you wilexit the program when you encounter the first number which doesnt satisfy ( maybe that's what you want .. but anyway you need to be clear on this ..

so you need a condition like

while ((num >=1) && (num <=1000) )

but i think you dont need the condition in the "while" anyway cos in that case if your file has

10

12

-1

3

4

5

the loop will exit when -1 is encountered

hence i think you should use the "rough steps" given at top and check for the numbers inside the loop

Hope I make myself clear .and dint confuse you more