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 months ago.
Improve this question
I was trying to multiply a double and an int but it shows nothing.
My code is:
#include <stdio.h>
int main()
{
double vergi = 0.01;
int fiyat = 20;
double sonuc = fiyat * vergi;
printf("%s", sonuc);
}
The %s specifier is for a String. As per the doc says, you should use the %f specifier in printf for a double result.
Wrong conversion type in printf.
You want to print variable which type is double.
This is correct - printf("%lf\n", sonuc);
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 3 years ago.
Improve this question
my function:
int compare(int A, int B){
if(A>B){
return A
}
else {
return B
}
}
int main(void)
{
int A;
int B;
scanf("%d", &A);
scanf("%d", &B);
compare (A,B);
}
but it is not returning, if i write print instead of return however, it works
It is correctly returning[1]; you simply don't do anything with the returned value. For example, if you wanted to print the returned value to stdout, you could use the following:
printf("%d\n", compare(A,B));
If it wasn't for the missing includes, the stray semi-colon, the two missing semi-colons, and the missing right brace that prevent the code from even compiling.
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
I am trying to use side effect operator in my expression which does not have just a variable. My program was compiled successfully but I got a runtime error "Segmentation fault"
Here is my code:
int main()
{
int x = 1;
printf(1 + (x++));
return 0;
}
C requires you to format the string, this way it knows what it should print. What you have in your example is nothing but memory addresses, which makes the C compiler confused.
int main()
{
int x = 1;
printf("%d\n", (1 + (x++)));
return 0;
}
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
The prototype (void example();) I have mentioned for the program is correct, but the compiler is giving garbage value instead of correct values in the output.
What codes should be added or removed?
Here is my code:
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
void example()
{
static int x = 10;
x=x+10;
printf("\n%d",&x);
}
int main()
{
int i;
for(i=0;i<=3;i++)
{
example();
}
getch();
return 0;
}
You are using an adress of a variable where printf wants just the value:
printf("\n%d",&x);
->
printf("\n%d",x);
Your result might also be improved by using "%d\n" instead.
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 7 years ago.
Improve this question
I'm trying to convert a float value to an int in C. I'm using print statements to see what's happening and making sure I'm getting the desired results, but something is not working correctly. Here is my code:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void){
float changeOwed = -1.00;
while(changeOwed < 0.00){
printf("How much change is owed?\n");
changeOwed = GetFloat();
}
printf("%f\n", changeOwed);
int centsOwed = roundf(changeOwed*100);
printf("%o\n", centsOwed);
If user input is, lets say 0.49, here is the output:
0.490000
61
I don't understand why the cast result is 61. I would expect normal errors to be a result of 0, 48 or 50, but I don't get this weird result and can't figure out the logic of it.
In case you don't get it yet ...
"061" is octal for "49".
Use printf("%d") instead of "%o" if you want to see a decimal "49".
Here is a good list of "printf" format options:
http://www.cplusplus.com/reference/cstdio/printf/