Compiling NONAME00.CPP:
Error NONAME00.CPP 46: Cannot convert 'unsigned int *' to 'int *'
Error NONAME00.CPP 46: Type mismatch in parameter 'a' in call to 'present(int
Warning NONAME00.CPP 79: Function should return a value
412 - Pi
Moderator: Board moderators
I tried compiling your code usung TC 3.0 and I get the following error message:
412 > need input/output, PLZ.
Greetings!.
Will really appreciate good input/output for this problem.
Also, what'll be the output for this?:
2
4
4
3
2
7
2
0
Thanks in advance.
Bernardo L.
Will really appreciate good input/output for this problem.
Also, what'll be the output for this?:
2
4
4
3
2
7
2
0
Thanks in advance.
Bernardo L.
Thanks!.
Greetings!.
Thanks for the quick response!
Going to try to solve it again...
Now, any other sugesstions for critic Input/Output?.
Thanks again!.
_.B._
Thanks for the quick response!

Going to try to solve it again...
Now, any other sugesstions for critic Input/Output?.
Thanks again!.
_.B._
412.....WA
[c]
#include<stdio.h>
#include<math.h>
int gcd(int x,int y);
main()
{
int n,i,j,pair,count,ratio,val[100];
float pi;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;++i)
scanf("%d",&val);
pair=0;count=0;
for(i=0;i<n-1;++i)
for(j=i+1;j<n;++j)
{
ratio=gcd(val,val[j]);
if(ratio==1)
++count;
++pair;
}
if(count>0)
{
pi = sqrt((6.0/(float)count)*(float)pair);
printf("%0.6f\n",pi);
}
else
printf("No estimate for this data set.\n");
}
}
int gcd(int x,int y)
{
int mod;
while(1)
{
mod=x%y;
if(mod==0)
break;
else
{
x=y;
y=mod;
}
}
return y;
}
[/c]
I think i am using the right algo. not only that i got correct answer for different inputs. But judges are always giving me WA.
can anybosy please help me to get out of the problem?

#include<stdio.h>
#include<math.h>
int gcd(int x,int y);
main()
{
int n,i,j,pair,count,ratio,val[100];
float pi;
while(1)
{
scanf("%d",&n);
if(n==0)
break;
for(i=0;i<n;++i)
scanf("%d",&val);
pair=0;count=0;
for(i=0;i<n-1;++i)
for(j=i+1;j<n;++j)
{
ratio=gcd(val,val[j]);
if(ratio==1)
++count;
++pair;
}
if(count>0)
{
pi = sqrt((6.0/(float)count)*(float)pair);
printf("%0.6f\n",pi);
}
else
printf("No estimate for this data set.\n");
}
}
int gcd(int x,int y)
{
int mod;
while(1)
{
mod=x%y;
if(mod==0)
break;
else
{
x=y;
y=mod;
}
}
return y;
}
[/c]
I think i am using the right algo. not only that i got correct answer for different inputs. But judges are always giving me WA.
can anybosy please help me to get out of the problem?

WA!!.
Greetings.
Why is it 3.000000 the output for?:
What will be output for this?:
Thanks in advance.
Why is it 3.000000 the output for?:
Code: Select all
3
2
7
2
0
Code: Select all
5
2
3
4
5
6
2
13
39
6
2
3
4
5
2
4
5
2
5
3
2
4
2
4
4
3
2
7
2
0
_.
Yeah, your code looks like it triggers integer division by mistake when printing out the estimate. You don't want integer division here. Try changing the 6 to 6.0 in your printf; that should trigger floating point division which you do want.
Or you can do as the previous poster suggested and change total and p to doubles.
Or you can do as the previous poster suggested and change total and p to doubles.
Computer Science is no more about computers than Astronomy is about telescopes.
-- E. W. Dijkstra
-- E. W. Dijkstra
412. Compile error....WHY!!!
I am really confused about this.
Why I get Compile error in this problem???
Here is my code:
[c]
#include <stdio.h>
#include <math.h>
int gcd(int p,int q)
{
if (q>p)
return(gcd(q,p));
int g;
if (q==0)
return(p);
g=gcd(q,p%q);
return(g);
}
int main()
{
int n; /*Number of Numbers*/
int num[52];
int i,j,x; /*Counters*/
int temp;
float tot;
float res;
while(1)
{
scanf("%d",&n);
temp=0;
if (n==0)
break;
for (i=1;i<=n;i++)
scanf("%d",&num);
for (j=1;j<i;j++)
for (x=j+1;x<i;x++)
if (gcd(num[j],num[x])==1)
temp++;
tot=n*((n-1)/2);
res=sqrt(tot);
if (temp==0)
printf("No estimate for this data set.\n");
else
printf("%f\n",res);
}
return 0;
}[/c]
Why I get Compile error in this problem???
Here is my code:
[c]
#include <stdio.h>
#include <math.h>
int gcd(int p,int q)
{
if (q>p)
return(gcd(q,p));
int g;
if (q==0)
return(p);
g=gcd(q,p%q);
return(g);
}
int main()
{
int n; /*Number of Numbers*/
int num[52];
int i,j,x; /*Counters*/
int temp;
float tot;
float res;
while(1)
{
scanf("%d",&n);
temp=0;
if (n==0)
break;
for (i=1;i<=n;i++)
scanf("%d",&num);
for (j=1;j<i;j++)
for (x=j+1;x<i;x++)
if (gcd(num[j],num[x])==1)
temp++;
tot=n*((n-1)/2);
res=sqrt(tot);
if (temp==0)
printf("No estimate for this data set.\n");
else
printf("%f\n",res);
}
return 0;
}[/c]
thanks a lot! I didn't know that.
I get this answer:
The code compiles in my computer (Dev-cpp Win98s) and works fine.
I think the function gcd is right!
Why says 'parse error before int'. and Why 'g undeclared'??? g is declared!!! I imagine there is some incompatibility between compiler in Linux and Windows, but I don't have Linux ...
so I don't know what is exactly wrong in my code...
someone knows????
I get this answer:
Why is that??02546511_24.c: In function `gcd':
02546511_24.c:8: parse error before `int'
02546511_24.c:11: `g' undeclared (first use in this function)
02546511_24.c:11: (Each undeclared identifier is reported only once
02546511_24.c:11: for each function it appears in.)
The code compiles in my computer (Dev-cpp Win98s) and works fine.
I think the function gcd is right!
Why says 'parse error before int'. and Why 'g undeclared'??? g is declared!!! I imagine there is some incompatibility between compiler in Linux and Windows, but I don't have Linux ...

someone knows????