Python <<
Previous Next >> Rust
ANSIC
Based on study.com: The C programming language was developed in the Bell Labs of AT&T by an employee called Dennis Ritchie between 1969 and 1973 while working on Unix operating system. He created this language using ALGOL, BCPL, and B the languages that were used before C was created. He added many powerful features to C and used it to further develop the UNIX operating system. American National Standards Institute (ANSI) in 1983, formed a committee to provide a comprehensive definition to the C language and thus came into existence the new ANSI C language with better features.
C Programming (1999)
Computer Programming in C for Beginners (2020)
// Our first program
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!\n");
return 0;
}
cp2022_ANSIC_w_tinyc_scite.7z (for cp2022 @gm users only) / cp2022_ANSIC_w_tinyc_scite.7z for @nfu
// from https://stackoverflow.com/questions/6127503/shuffle-array-in-c
#include <stdio.h> //for printf()
#include <stdlib.h> //for srand() and rand()
#include <time.h> //for time()
#include <memory.h> //for memcpy()
// 作業, 請計算各數值在各位數出現的總數, 是否依照亂數機率出現?
// 作業, 請將此程式改用 Brython 編寫.
void main ()
{
int elesize = sizeof (int);
int i;
int j;
int r;
int num = 10;
int times = 50;
int src [num];
int tgt [num];
srand ( (unsigned int) time (0) );
for (j = 0; j < times; j++)
{
for (i = 0; i < num; src [i] = i++);
for (i = num; i > 0; i --)
{
r = rand () % i;
memcpy (&tgt [num - i], &src [r], elesize);
memcpy (&src [r], &src [i - 1], elesize);
}
for (i = 0; i < num; printf ("%d ", tgt [i++] ) );
printf("\n");
}
}
利用 Differential Evoluation (差分進化演算法), 以 ANSI C 程式語言編寫適應方程式的最大化或最小化演算:
volume_in_de_ex1.c
其他範例程式
相同演算法, 以 CPython 解題:
volume_in_de_ex1.py
相同演算法, 以 Brython 解題.
此一採固定表面積的紙盒體積最大化運算範例, volume_in_de_ex1.py 的原始作者為李孟恭 (https://github.com/kmollee/algorithm/blob/master/de.py)
從 lw-oopc 的簡介 以及升級版 lw-oopc 原始碼中, 則可以進一步對 ANSI C 在嵌入式 (embedded) 系統上的應用有所了解.
Python <<
Previous Next >> Rust