qianqianling 发表于 2017-5-8 06:49:34

c 和Python 写个小程序在shell中运行。

 c的话,命名a.c
运行:   gcc -o a a.c
./a
代码:
#include <stdio.h>
float a1 = 1.5;
float a2 = 1.8;
float b2 = 2.0;
int main(){
for(int a = 1; a <= 5; a++){
    for (int b = 1; b <= 5; b++){
        float result1 = (a1 * b2)*a - (a+b);
        float result2 = (a2 * b2)*b - (a+b);
        if (result1 > 1 && result2 > 1){
            printf("result1==%.2f,result2==%f,a===%d,b==%d",result1,result2,a,b);
            }
        }
    }
return0;
 
}
 
 
 
 
 
pythone 命名 a.py 
运行 Python a.py 
代码
a1 = 1.5
a2 = 1.8
b2 = 2.0
for a in range(1,5):
    for b in range(1,5):
        result1 = (a1 * b2)*a - (a+b)
        result2 = (a2 * b2)*b - (a+b)
        if (result1 > 1.0 and result2 > 1.0):
 
            print "result1="+str(result1),"result2="+str(result2),"a="+str(a),"b="+str(b)
 
 
 
页: [1]
查看完整版本: c 和Python 写个小程序在shell中运行。