I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Products » Calculator »

Creating New Calculators

You can create a new Instant Calculator any time by merely submiting a function to CodeCogs at: http://www.codecogs.com/submit.php?mode=NEW

Once you have submited and confirmed the function, it will pass through our QA system and on acceptance will be compiled for use as an Instant Calculator. This process usually takes 24hrs.

Important Note: If you wish to keep the content of your function private you should select 'Private' under Licence Type, otherwise your component will be added to the CodeCogs Library where others could gain access to the code.

Example 1

Imagine you want to solve this well know dynamics equation in mechanics: v^2=u^2+2as. Returning the final velocity (v) for a given initial velocity (u) and acceleration (a) over the distance (s). First we need a slight rearrangement of the equation, i.e.:


Now we can write the code:


double velocity(double u, double a, double s)
  return sqrt(u*u + 2*a*s);

Color Key:

  • We're doing some slightly complex maths, due to the square root (sqrt in C), so we'll include the C maths library (i.e. #include <math.h>).
  • All our variable are real numbers, so for maximum precision we'll use the C data type called 'double'.
  • And our function also returns a real number, so the type before the function name will also be 'double'.

If you now goto the Submission system and submit the above code, you'll see the calculator generated. Remember it won't work immediately, it'll have to pass through our QA process first.

Example 2

The previous example was very mathematic, but lets say you want a calculator that counts the number of letters in a sentence. Points to consider:

  • A word must have letters a to z, in either upper or lower case. If you look at an appropriate ASCII table, you see that:
    • A to Z are represented in a computer with numbers 65 to 90
    • a to z are represented with numbers 97 to 122
  • We don't need any other C function libraries, so we won't be using #include
  • We'll accept a pointer to character string, which is written as 'char*'. This will be terminated by a zero (0) - a standard thing in C.
  • And we'll return the number of letter using an integer, which is C is represented by 'int'

So now to the code:

int lettercount(char* string)
  int count=0;
  int i=0;
    if((string[i]>=65 && string[i]<=90) || (string[i]>=97 && string[i]<=122)) count++;
  return count;

Again goto the Submission system and see what happens.

The submission system will try to create as much documentation as possible. But it can't possible know what you are ultimately trying to do. Therefore to make your calculators more user friendly make sure you document at the very least each of the input parameters.

Further documentation

As the entire system is based on the C computer programming language, then if you need help learning this language consider the following links

Please remember when using any tutorials that the CodeCogs system only accepts functions not complete programs. Therefore you should never enter the function called main(...), as we need that ourselves to create a wrapper around your code.