Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
In the main() function,
i,a and b are decalred static. Ok, fair enough.
The function is called.
All i,a and b have some value. Ok, fair enough.
The function is called again.
Now as a static variable i , a and b must retain their value.
But
How is i again intialised to 0? (Shouldnt it contain its previous value?)
Snap shot of the problem.
P.s Answer is d btw.
i is not initialized again:
void printtab()
{
static int i, a = -3, b = -6;
i = 0;
...
It is assigned a new value when the function is entered.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
151A codeforces link
Here is my code written in C language. It has some problem
#include<stdio.h>
#include<conio.h>
int main ()
{
int n,k,l,c,d,p,nl,np,mm,per,tl,to,sum;
scanf("%d%d%d%d%d%d%d%d",&n,&k,&l,&c,&d,&p,&nl,&np);
mm = k*l;
per = mm/nl;
tl = c*d;
to = p/np;
sum=(per,tl,to)/n;
printf("%d",sum);
return 0;
}
You have to find the minimum value among per, tl, and to and divide that with n instead of just calculating to/n, which you are currently calculating with sum=(per,tl,to)/n;. (per and tl are ignored according to the definition of the comma operator)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm creating a code where someone enters the amount of people eating a cut from and from there I can figure out how many pieces I can have in one pizza.I'm having trouble and don't know how to fix my error.
#include <stdio.h>
int Cuts(int n)
{
int max = n*2;
return m;
}
int main()
{
int m;
m = Cuts();
printf("P1:%d\n" , m);
}
Your CutYourPizza function is written to require one integer argument (called n), but when you invoked that function on the line max = CutYourPizza(); you did not supply any argument.
For example, if you wanted to supply the number 10 as an argument, then you could have written max = CutYourPizza(10); with the argument 10 inside the parentheses.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm debugging a piece of code and found that when I print out a variable prior to function execution it is nonzero. The same variable is then used as an input argument for a function, but when printing it out right at the beginning of that function it says it's zero.
Outside the function call it looks like this:
printf("sigma_b_m: %f \n",sigma_b_m);
oprq_init(sigma_b_m, b_m, r_m, x, P);
Inside the function call I did the following:
void oprq_init(const float sigma_b_m, const float b[3], const float r[3], float K[16], float P[256]) {`
printf("sigma_b_m: %f \n",sigma_b_m);
}
I removed the rest of the function for clarity but the printf line is really at the very start of the function.
The output is then:
sigma_b_m: 0.001745
sigma_b_m: 0.000000
Any idea how it now registers as zero rather than the 0.001745 it told me it was prior to going into the function?
Ok I realized my own dumb mistake... the header file had a typo in the #ifndef statement... I'm sorry for the trouble guys and my obstinacy.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Here is the source codeļ¼
#include <stdio.h>
enum coordinate_type{ RECTANGULAR = 1,POLAR };
int main(void)
{
int RECTANGULAR;
printf("%d %d\n",RECTANGULAR,POLAR);
return 0;
}
Why is the result the following:
3 2
You are redefining what RECTANGULAR is in the main function. It gets initialized with a "random" value, in this case it is 3, but it could be anything else.
POLAR keps its value of 2 because of how the enum is defined.
Try redefining the RECTANGULAR variable in main to see different outputs.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Spot all bugs in the code snippet below
uint arr[100]
for (uint i=99; i >=0; i--)
arr[i] = 0;
This is a question for the test, can anybody point me to all bugs in this snippet
uint isn't a type.
The first line is missing a semicolon.
i >= 0 is always true.
arr[0U - 1] is undefined behavior because it access outside the bounds of the arr array.
It's not clear that this snippet is running as part of a function. If it is not, then the entire for-loop is a syntax error.
Additionally, if this class is taking place before 1999, then:
You can't declare variables in a for loop. Instead, the uint i should be declared before the loop.
This code should probably be rewritten as simply:
unsigned arr[100] = {0};