C program with math.h

Re: C program with math.h

de către Utpal Das-
Număr de răspunsuri: 7

Sure. While editing the question, use Customization and specify Parameters under Advanced Customisation as:

{"linkargs":["-lm"], "compileargs": ["-std=gnu99"] }

Specifying linkargs is essential for math.h, and compileargs is required for M_PI (refer link for details).

Ca răspuns la Utpal Das

Re: C program with math.h

de către Miguel López-

Many, many  thanks for your last answer it Works perfectly. Now, is there any kind of question in coderunner to process pseudocode ?

Ca răspuns la Miguel López

Re: C program with math.h

de către Richard Lobb-

There's no built-in question type for this. You can define your own question types but the problem with processing pseudo code is that by its very nature it has no formal specification. It's *pseudo* code. So how would you define whether it was right or not?

You could specify a basic set of pseudo-code control structures that students were obliged to follow and then check for the expected ones but even that's likely to be ill-defined. There are usually multiple ways of solving a problem, and *while* and *for* loops are potentially interchangeable. The principle behind CodeRunner is that correctness is determined by executing the code to see if it does the right thing. That's just not possible with pseudocode.

Ca răspuns la Richard Lobb

Re: C program with math.h

de către Miguel López-

Thank you for your kind and very complete response. So, strictly establishing the set of structures to be used in pseudocode (like a programming language) and having a compiler for that set, would it be possible?
Ca răspuns la Miguel López

Re: C program with math.h

de către Miguel López-

Although recognize the sqrt function, don't recognizes the pow function, what might be happening?

Ca răspuns la Miguel López

Re: C program with math.h

de către Richard Lobb-

We need more information to answer this question.

I suggest you first click the Template Debugging checkbox in the question editing form, save the question with validation turned off, then run it from a question preview window. If you study the code that's run, you will likely be able to spot the problem yourself. If not, please paste the code that's being run into your next posting, tell us what question type you're using, and include a screen dump showing what error you're getting, or at least the text of the error message.

Ca răspuns la Richard Lobb

Re: C program with math.h

de către Miguel López-

Hi, I'm using the c_via_python question type.

Here's the code:

#include <stdio.h>
#include <math.h>
int main()
{ int cont, nc, ng;
printf(\"No. de casillero: \");
scanf(\"%d\", &nc);
for(cont=1; cont <=nc; cont++)
{
ng = pow(2, cont-1); 
printf(\"%d \", ng);
}
}

and, here's the error: 

***Error*** /tmp/ccmzaEe7.o: In function `main': prog.c:(.text+0x68): undefined reference to `pow' collect2: error: ld returned 1 exit status ** Compilation failed. Testing aborted **

Template's parameters:

{"linkargs":["-lm"], "compileargs":["-std=c89"] }

Ca răspuns la Miguel López

Re: C program with math.h

de către Richard Lobb-

The linkargs and compileargs sandbox parameters are relevant to C jobs but you're actually running a Python job. Those parameters aren't relevant to Python.

The c_via_python question type is not intended to be the primary way to run a C program. It's an example of how to implement a different language by writing a Python script to compile and run a program in that new language. The commands to compile and build the C program are embedded within the Python script. If you wish to set compile args and link args for this question type you'll have to insert them into the Python script.

Or you can just go back to using one of the built-in C question types like c_function or c_program, as you apparently were doing at the start of this thread.