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 ;
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 1 year ago.
Improve this question
I have a problem that this code doesn't end with output.
I appreciate if help me.
#include <stdio.h>
int main(){
int number,counter=0;
scanf("%d",&number);
while (number!=0){
number=number/10;
counter++;
}
printf("the number has %d digits",&counter);
return 0;
}
You should remove "&" from your printf statement.
& is for scanning not printing
the correct form is :
printf("the number has %d digits",counter);
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
Im new to C.
I dont understand i have the " in front of the %d
#include <stdio.h>
int x,y;
int main(void)
{
printf("Indtast 2 numre du vil bytte rundt på \n");
scanf("%d", &x);
scanf("%d", &y);
printf("Dette er dine numre byttet rundt! %d, %d", y, x);
return 0;
}
The code you posted here looks fine. However, looking at the title, you seem to have missed double-quotes around %d on line 7. Save the code you just posted, and recompile. Next time, please post the compiler you are using, too.
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
#include <stdio.h>
#include <stdlib.h>
main()
{
int n;
printf("Introduce un número entero\n");
scanf("%d", &n);
printf("Has introducido el número: %d", &n);
}
Every time I run this C code I get 6487628 for n, I have uninstalled and installed it over and over again and it keeps doing that, I don´t know what else to do.
You don't want the &n in the printf(), you want n. You are displaying the memory location n is stored in
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
#include <stdio.h>
int main (void)
{
int hist,geo,phy,chem,bio;
int credits=0;
printf("Enter marks in history : ");
scanf("%d",&hist);
if(hist>40)
credits =10;
else
printf("No credits awarded for history");
printf("Credits obtained is %d",&credits);
return(0);
}
when I run the code, and I get a value of 230586 for the variable 'Credits'. Please help. I am a beginner in C
&x is like asking a question "What is the address of variable x?" , that's why you get the strange number. In order to print the variable value, please pass credits instead of &credits to the printf function.
printf("Credits obtained is %d", credits);
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 8 years ago.
Improve this question
I am trying to make a program in C to find the approximate square root of a number using the formula NG = 0.5( LG + N/ LG). So far i have:
#include <stdio.h>
#include <math.h>
int main(){
double n;
double LG=1;
double NG;
printf("Enter number");
scanf_s("%lf",&n);
do{
NG=(.5*(LG+n/LG));
LG=NG;
}while((NG*NG-n)<.005);
printf("The root is %lf",NG);
}
This structure works fine in java, but the loop doesn't seem to be executing in C.
Thanks for any advice.
You do not want to loop while NG*NG-n is less than .005. You want to loop while NG*NG is farther from n than desired.
The distance between NG*NG and n is fabs(NG*NG - n).