sim-C入门
·
我们非常感谢我们对 sim-C 的支持。如果您已经登陆这里并想了解更多关于 sim-C 的信息,请查看我们之前的帖子此处。
在这篇文章中,我们将看到安装 sim-C 的各种方法和一些示例,让您熟悉这个神奇的工具。所以让我们用 sim-C 来简化 C 语言的编程。
在 Mac/Linux/Windows 上安装
1.运行以下命令
$ pip install git+https://github.com/cimplec/sim-c
在您的系统上安装 sim-C 后,我们就可以开始使用它了。您可以查看文档以熟悉 sim-C 的高级语法。
运行步骤
-
打开您选择的任何文本编辑器。
-
使用 sim-C 高级语法编写代码。
-
使用 sim-C 编译器运行文件。
$ simc test.simc
生成的 C 代码文件与 simc 文件同名,但扩展名为 .c
以下是一些 sim-C 的实际应用示例。
下面的代码是用 sim-C 的语法编写的。
MAIN
// A single line comment
/*
and this
is a
multi-line comment
*/
for a in 1 to 10 by +1 {
if (a%2==0){
print(a)
}
else {
print("Odd")
}
}
END_MAIN
这个 sim-C 代码被转换为——
#include <stdio.h>
int main() {
// A single line comment
/*
and this
is a
multi-line comment
*/
for(int a=1; i<=10; i++) {
if (a%2==0){
printf("%d", a);
}
else {
printf("Odd");
}
return 0;
}
这是另一个例子:
sim-C 代码 —
def interest(x, y, z) {
si = (x*y*z)/100
return si
}
MAIN
var p= input(“Enter the principal amount: “, “f”)
var r= input(“Enter the rate: “, “f”)
var t= input(“Enter the time period: “, “f”)
var interest_amount = interest(p, r, t)
print(interest_amount)
END_MAIN
等效的 C 代码 —
#include <stdio.h>
float interest(float x, float y, float z) {
float si = (x*y*z)/100;
return si;
}
int main(){
float p;
printf("Enter the principal amount: ");
scanf("%f", &p);
float r;
printf("Enter the rate: ");
scanf("%f", &r);
float t;
printf("Enter the time period: ");
scanf("%f", &t);
float interest_amount = interest(p,r,t);
printf(interest_amount);
return 0;
}
很明显,sim-C 能够通过减少需要编写的代码量来提高生产力并缩短开发时间。
sim-C 仍在持续开发中,并且正在发生一些惊人的变化!请查看Github repo并为其加注星标,以便及时了解正在发生的更新。如果您对我们有任何建议,请告诉我们。期待您的回音。
更多推荐


所有评论(0)