#include <stdio.h>
#include <stdlib.h>
void csub(void) {
int valueOne , valueTwo;
valueOne = rand() % 10 + 1;
valueTwo = rand() % 10 + 1;
print("Max random value %d\n" , RAND_MAX );
print("two generated Numbers %d , %d \n" , valueOne , valueTwo );
}
%s/print/printf/g 로 print를 printf 로 변경한다. (치환)
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void csub(void);
int main(int argc , char* argv[] ) {
csub( );
return 0;
}
gcc –c ex_main.c
gcc –c ex_sub.c
gcc ex_main.o ex_sub.o –o ex_run.out
./ex_run.out
참고로 C언어로 작성한 프로그램을 컴파일하려면 CC 컴파일러가 필요하다. 리눅스의 C 컴파일러는 gcc이다.
행 파일의 이름을 지정하지 않았기 때문에 a.out으로 생성되고, ex_run.out이라는 실행 파일이 생긴걸 볼 수 있다.
class Coord{
private int pos_x;
private int pos_y;
public Coord( int pos_x , int pos_y) {
this.pos_x = pos_x;
this.pos_y = pos_y;
}
public int getPos_x() {
return pos_x;
}
public int getPos_y() {
return pos_y;
}
public void setPos_x(int a) {
pos_x = a;
}
public void setPos_y(int a) {
pos_y = a;
}
public void moveXY(int x,int y) {
pos_x += x;
pos_y += y;
}
public String toString(){
return "coordinate X:" + pos_x + " Y:" + pos_y ;
}
}
class Example1 {
public static void main(String[] args) {
Coord crd1 = new Coord(10,20);
System.out.println( crd1.toString() );
crd1.setPos_x(10);
crd1.setPos_y(20);
System.out.println( crd1.toString() );
crd1.moveXY(20,30);
System.out.println( crd1 );
System.out.println("X:" + crd1.getPos_x() + " Y:" + crd1.getPos_y());
}
}
#python example
x = int( input("enter the first number:") )
y = int( input("enter the second number:") )
sum = x + y
avg = float(sum) / 2
print("sum : " , sum)
print("average : " , avg)
python3 명령어를 이용해서 파이썬 파일을 실행한다