Download on AppStore.
Turn your mobile device into a real computer
What makes a computer a computer? Actually, it follows from its name, derived from the word compute - compute. Yes, he has to calculate. But not as a calculator or even a programmable calculator. Computer must give us the opportunity to program complex calculation algorithms, enter the source data and get results not only in the form of numbers, but also texts, charts and graphs.
Nano Cis a C language interpreter for the iPhone and iPad. Nano C allows arbitrary calculations on your mobile device and display the results in text and graphical representation.
Program and its results can be sent to email. Wildcards are supported for fast input of language constructs.
This version has the following elements of the C language:
- Operator if – else
- Operator switch
- Looping operators for, while, do - while. Supported break and continue.
- Variables int, float, char.
- Arrays of types int, float, and char.
- Functions of types void, int, float and char. Operator return.
- Mathematical Functions abs, acos, asin, atan, ceil, cos, random, exp, fabs, floor, log, log10, rint, sin, sinh, sqrt, tan, tanh, atan2, fmod, pow.
- Text output functions printf, print.
- Console input function get.
- Specific functions of graphical output moveto, line, circle, pixel, setcolor, setwidth.
- Specific charting functions linechart, barchart, piechart.
- Function sizeof.
- Functions chr, ord, strcmp, strlen, strchr, strstr, strlwr, strupr, substr, str_replace.
- Operators +, -, *, /, %, <, >, <=, >=, ==, !=, ++, --, +=, -=, /=, *=, %=.
Examples of C programs
1. Variables
float gl_a, gl_b; // Global variables
int main()
{
// Local variables
int x = 5, y = 6, z;
char c = 'Some text';
gl_a = 8.25;
z = x * y + 3 - gl_a;
if(z > 10) print('text 1'); else print('text 2');
print('Hello, World! ' + z);
}
2. String functions
void main()
{
char str1 = "Hello";
char str2 = "World";
char str3;
int len;
// copy str1 into str3
str3 = str1;
printf("strcmp(str1, str3) : %d\n", strcmp(str1, str3));
printf("strcmp(str1, str2) : %d\n", strcmp(str1, str2));
// concatenates str1 and str2
str1 = str1 + str2;
printf("strcat(str1, str2): %s\n", str1);
// total lenghth of str1 after concatenation
len = strlen(str1);
printf("strlen(str1) : %d\n", len);
// Find character in string
printf("strchr(str1, 'y'): %d\n", strchr(str1, 'y'));
printf("strchr(str1, 'W'): %d\n", strchr(str1, 'W'));
// Find string in string
printf("strstr(str1, 'lli'): %d\n", strstr(str1, 'lli'));
printf("strstr(str1, 'llo'): %d\n", strstr(str1, 'llo'));
// Convert string to lowercase
printf("strlwr(str3): %s\n", strlwr(str3));
// Convert string to uppercase
printf("strupr(str3): %s\n", strupr(str3));
// Substring of a string
printf("substr(str1, 2, 5): %s\n", substr(str1, 2, 5));
// Replace all occurrences of substring
// str_replace (string, substr, replacement)
printf("str_replace (str1, 'o', 'a'): %s\n", str_replace (str1, 'o', 'a'));
}
3. Arrays and loops
int main()
{
// Arrays without data
int ar[];\n
// An array with data
char ch[] = {'one', 'two', 'three'};
// Array size of 100 cells
float f[100] = {1.5, 2.2, 3};\n
// Add data to array
for(int i = 0; i < 5; i++)
{
ar[] = i * 10;
}\n
print('Data from array ar');
// Print data from an array
for(i = 0; i < sizeof(ar); i++)
{
print(ar[i]);
}\n
// For loop
print('');
print('for');
for(int j = 0; j < sizeof(ch); j++) { print(ch[j]); }
// do-while loop
print('');
print('do - while');
i = 0;
do
{
print( ++i * 5);
} while(i < 5)\n
// while loop
print('');
print('while');
int x = 5;
while(x > 0)
{
print(x--);
}
}
4. Factorial
int main()
{
int number = get('Enter a number');
int fact = 1;
printf('%d! = %d', number, factorial(number));
}
int factorial(int n)
{
int result = 1;
for (int c = 1; c <= n; c++)
{
result = result * c;
}
return result;
}
Screenshots
Limitations of Nano C
- Blocks of cycle operators should always be enclosed in braces.
- Limited library of standard functions, which will be expanded in future releases of the program.
Description of built-in features of Nano C.
- Print – Outputs the text information to the screen. Always prints a new line.
Format print(, , ….);
Examples
Print(‘Hello, World!’);
Int x = 10;
char name = “John”;
print(“Hi, ”, name, “. You get ”, x * 2 + 3);
- Printf – Outputs formatted text information to the screen
Format printf(<String with format>, <Value of placeholder 1>, <Value of placeholder 2>…);
Examples
Printf(‘Hello, World!’);
Int x = 10;
char name = “John”;
printf(“Hi, %s . You get %d”, name, x * 2 + 3);
Types of supported placeholders %s – string, %d – integer, %f – float.
- get – Console input function.
Format get(<Message>);
Example
char name = get('What is your name?');
print(“Hi, ”, name);
char c;
while((c = get("Enter your name")) != '')
{
printf("Hi, %s\n",c);
}
- Sizeof – Size of the variable.
Calculates the length of the string or the number of elements in the array.
- Moveto – Move to the specified coordinates.
Format moveto(<X>, <Y>);
- Line (Addline) – Draw a line from the current position to the specified coordinates.
Format line(<X>, <Y>);
- Circle – Draw a circle
Format circle(<X>, <Y>, <Radius>);
- Pixel – Draw a point
Format pixel(<X>, <Y>);
- Setcolor – set the line color
Format setcolor(<R>, <G>, <B>); // RGB 0...255
- Setwidth – set line thickness
Format setwidth(<Line thickness>);
- linechart – Draw a line chart
Format linechart(<an array of values>, <an array of names>);
Example
float vals[] = {-10,-24,14};
char labels[] = {'January', 'February', 'March'};
linechart(vals, labels);\n"
Example of multi line chart
float vals[];
vals[] = {-10,-24,14,18,28};
vals[] = {10,24,20,18,16};
vals[] = {20,30,25};
char labels[] = {'January', 'February', 'March', 'April', 'May'};
linechart(vals, labels);
- barchart – Draw a bar chart
Format barchart(<an array of values>, <an array of names>);
Example
float vals[] = {-10,-24,14};
char labels[] = {'January', 'February', 'March'};
barchart(vals, labels);\n"
Example of multi bar chart
float vals[];
vals[] = {-10,-24,14,18,28};
vals[] = {10,24,20,18,16};
vals[] = {20,30,25};
barchart(vals, labels);
- piechart – Draw a pie chart
Format piechart(<an array of values>, <an array of names>);
Example
float vals[] = {10,24,14,18,28,40,30,20,15,16,8,4,3,1};
char labels[] = {'January', 'February', 'March', 'April', 'May'};
piechart(vals, labels);\n"