# Help with a curious C problem please

Discussion in 'C' started by adriancdperu, Jul 10, 2008.

Joined:
Jul 10, 2008
Messages:
1
0
Trophy Points:
0
Hello world, my name is adrian and im a newbie...

]m trying to write a program which tests whether a natural number can be written as the sum of the squares of two not null integers. I am using an auxiliary function to test whether a natural number is a square or not. Seems that compiling errors are produced even by this initial function
Cant figure out whats wrong though....
Please somebody help im a big ****....

what i did is this:

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

int sqtest (double n);
{
int a;
if(double sqrt(n)==double floor (sqrt(n)))
a=1;
else
a=0;
return a;
}

int main ()
{double n, i, a;
a=0;
i=1;
printf("input n\n");
scanf("%d",&n);
while ((i<=double sqrt(n))&&(sqtest(n-i*i)!=0))
{i=i+1;
}
if(i<double sqrt(n))
printf("n decomposable as sum of squares of:\n" i, double sqrt(n-i*i));
else
printf("n indecomposable nontrivially\n");
return();
}
```
====================================
figured out that there might be not necessity of putting the "double", so i took them out and the code changed into sth like this:

Code:
```int sqtest (double n);
{
int a;
if(sqrt(n)==floor (sqrt(n)))
a=1;
else
a=0;
return a;
}```
..........................

but still it does not work
can sb help me please im really in a big --------

Joined:
Jul 18, 2008
Messages:
101