Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I started to read about pointers and I tried to write code for a problem in which the user gives me the radius of a circle and I return to him the perimeter and the surface. When I run this code the compiler shows this :
example.c:16:15: error: expected ‘)’ before ‘float’
void circle(r,float *p,float *s)
^
My code:
#include <stdio.h>
float pi=3.14159;
void circle(float ,float *,float *);
int main()
{
float radius,perimeter,surface;
printf("insert the radius of the circle\n");
scanf("%f",&radius);
circle(radius,&perimeter,&surface);
printf("the perimeter is %f and the surface is %f\n", perimeter, surface );
return 0;
}
void circle(r,float *p,float *s)
{
*p=2*pi*r;
*s=pi*r*r;
}
You are missing the radius:
you typed: circle(r,float *p,float *s)
but what is r in the parameter? correct this by doing:
void circle(float r, float *p,float *s)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
So, I am supposed to print out the following series using a C program:
I decide to use a recursive approach and come up with this code:
#include<stdio.h>
float series(int n, float x)
{
float prod;
if(n==1)
return 1;
else
{
prod = (x*x)/((2*n-2)(2*n-3)); //line 10
return prod*series(n-1,x);
}
}
int main()
{
int n;
float x;
printf("\n Enter the values of n and x : ");
scanf("%d %f",&n,&x);
printf("\n The series is :");
for(int i=1;i<=n;i++)
printf(" %f,",series(i,x));
printf("\n\n");
return 0;
}
But this gives an error on line 10:
error: called object type 'int' is not a function or function pointer
I don't see any syntactical error on the line. It would be great if you could point it out.
Thank You!
prod = (x*x)/((2*n-2)(2*n-3)); //line 10
should be
prod = (x*x)/((2*n-2)*(2*n-3)); //line 10
The compiler sees this as a function call where 2*n-2 is the function pointer and 2*n-3 is the argument.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have the following code but it gives me a completely random answer. Why?
#include <stdio.h>
#define PI 3.141
//function prototypes//
double get_h_area(double r);
int main()
{
double r=5.5;
printf("A=%d\n",get_h_area(r)); //prints the answer
return 0 ;
}
double get_h_area(double r)
{
return PI*r*r; //returns the answer
}
But the result I get is: -618475291
The expected result is: 95.03
Use this :
#include <stdio.h>
#define PI 3.141
//function prototypes//
double get_h_area(double r);
int main()
{
double r = 5.5;
printf("A=%lf\n", get_h_area(r)); //prints the answer
return 0;
}
double get_h_area(double r)
{
return PI * r * r; //returns the answer
}
As #Achal told you.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm a new learner to C and I have found this program which is to find the area of a circle. However my compiler keeps throwing this error at me:
[Error] C:\Users\Jiachenn\Documents\C-Free\Projects\HelloWorld\main.c:11: error: syntax error before "printf"
This is my code:
#include <stdio.h>
#include <conio.h>
main()
{
int radius;
float pi =3.14f, area;
clrscr();
printf("Input the radius:");
scanf("%d",&radius);
area = pi*radius*radius
printf("\n Area of circle= %f", area);
getch();
}
Do help!
You are just missing the semicolon on the end of line
area = pi*radius*radius ;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to compile a programme in c but I keep getting the same two errors. The errors I get are:
error: expected ‘)’ before ‘idSubject’
printf("%d" idSubject);
and the other one:
format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
Here's the code:
#include <stdio.h>
#include <stdlib.h>
void averageMark (idSubjectE) {
typedef enum {FALSE,TRUE} bool;
int i;
float acum;
int idChair;
int idSubject;
int numEst;
float mark;
bool found=FALSE;
scanf("%d", &idChair);
printf ("%d", idChair);
scanf("%d", &idSubject);
while (idSubject!=0) {
scanf("%d", &numEst);
if (idSubject==idSubjectE) {
printf("%d" idSubject);
found=TRUE;
for (i=1; i<numEst*2; i++) {
if (i%2==0){
scanf("%f", &mark);
acum=acum+mark;
}
}
printf("%f", acum/(float)numEst);
}
scanf("%d", &idSubject);
}
}
int main(){
averageMark(12);
}
I've been trying and trying but I can't find the mistake,
change printf("%d" idSubject); to printf("%d", idSubject); notice the ,
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
The code runs perfectly when I arbitrarily pass arguments to the area function. But gives me a segmentation fault when I try to run the loops. Given n<100
Here's my code.
#include<stdio.h>
#include<math.h>
double area(int x,int y,int x1,int y1,int x2,int y2)
{ //Heron's formula
double a,b,c,s;
double abc;
a=sqrt(((x-x1)*(x-x1))+((y-y1)*(y-y1)));
b=sqrt(((x-x2)*(x-x2))+((y-y2)*(y-y2)));
c=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
s=(a+b+c)/2;
abc=sqrt(s*(s-a)*(s-b)*(s-c));
return(abc);
}
int main(void)
{
int n,i,j,k;
double max=0,z=0;
scanf("%d",&n);
int x[100]={},y[100]={};
for(i=0;i<n;i++)
{
scanf("%d %d",&x[i],&y[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
for(k=j+1;k<n;j++)
{
z=area(x[i],y[i],x[j],y[j],x[k],y[k]);
printf("%lf\n",z);
if(z>max)
{
max=z;
}
}
}
}
//printf("\n%lfoi\n",area(0,0,1,0,1,2));
printf("%lf",max*2);
}
The inner loop is incrementing j, it should probably increment k:
for(k=j+1;k<n;j++)
^
oops!
there is an error index in inner loop: should be
for(k=j+1;k<n;k++)
instead of
for(k=j+1;k<n;j++)
for(k=j+1;k<n;j++)
I think you meant to increment k in this loop, not j.
You have to increase "k" not "j"
for(k=j+1;k<n;k++)
{ }