프로그래밍 605

(최대공약수 구하기) while... 반복문 예제 for C

소스 파일명: testWhile.c /* * Filename: testWhile.c * * Purpose: Example using the while loop syntax * while .... * * Compile: cl testWhile.c * * Execute: testWhile -200 300 */ #include #include // 사용법 표시 void printUsage() { printf("Using: testWhile [integer1] [integer2]\n"); printf("This finds the greatest common divisor of the given two integers.\n"); } int main(int argc, char *argv[]) { long val1,..

프로그래밍/C 2008.02.21

(최대공약수 구하기) while... 반복문 예제 for Lua

소스 파일명: testWhile.lua --[[ Filename: testWhile.lua Purpose: Example using the while loop syntax while .... Execute: lua testWhile.lua -200 300 --]] -- 사용법 표시 function printUsage() print "Using: lua testWhile.lua [integer1] [integer2]" print "This finds the greatest common divisor of the given two integers." end if #arg ~= 2 then printUsage() os.exit(1) end -- 명령행 인자의 두 스트링을 가져와서 -- 정수 타입으로 변환하여 ..

프로그래밍/Lua 2008.02.21

(최대공약수 구하기) while... 반복문 예제 for Python

소스 파일명: testWhile.py # coding=euc-kr # Filename: testWhile.py # # Purpose: Example using the while loop syntax # while .... # # Execute: python testWhile.py -200 300 # import sys # 사용법 표시 def printUsage(): print "Using: python testWhile.py [integer1] [integer2]" print "This finds the greatest common divisor of the given two integers." if len(sys.argv) != 3: printUsage() sys.exit(1) # -----------..

(최대공약수 구하기) while... 반복문 예제 for Ruby

소스 파일명: testWhile.rb # # Filename: testWhile.rb # # Purpose: Example using the while loop syntax # while .... # # Execute: ruby testWhile.rb -200 300 # # 사용법 표시 def printUsage() print "Using: ruby testWhile.rb [integer1] [integer2]\n" print "This finds the greatest common divisor of the given two integers.\n" end if (ARGV.length != 2) printUsage() exit(1) end # ----------------------------------..

Groovy 언어의 특징을 잘 나타내는 몇 가지 예제들

간단한 Groovy 스크립트:def name='World'; println "Hello $name!" 다소 복잡한 Groovy 스크립트: class Greet { def name Greet(who) { name = who[0].toUpperCase() + who[1..-1] } def salute() { println "Hello $name!" } } g = new Greet('world') // 객체 생성 g.salute() // "Hello World!"를 출력 Apache의 commons.lang 라이브러리를 이용한 스크립트 (한 개의 소스 파일로 저장한다.): class Greet { def name Greet() { } Greet(who) { name = who[0].toUpperCase() +..

(최대공약수 구하기) while... 반복문 예제 for Groovy

아래의 소스 코드는 Groovy로도 실행되는 Java 용 소스파일 TestWhileLoop.java를 Groovy 용으로 Groovy 언어 답게 고친 것이다. 소스 파일명: testWhile.groovy /* * Filename: testWhile.groovy * * Purpose: Example using the while loop syntax * while .... * * Execute: groovy testWhile.groovy -200 300 * */ // java.lang.Math 클래스를 명시적으로 import하는 구문이 없어도 // Groovy는 이 클래스를 자동으로 import한다. // 사용법 표시 def printUsage() { println 'Using: groovy testWhil..

(최대공약수 구하기) while... 반복문 예제 for Java

소스 파일명: TestWhileLoop.java /* * Filename: TestWhileLoop.java * * Purpose: Example using the while loop syntax * while .... * * Compile: javac -d . TestWhileLoop.java * Execute: java TestWhileLoop -200 300 * */ import java.lang.Math; public class TestWhileLoop { // 사용법 표시 public static void printUsage() { System.out.println("Using: java TestWhileLoop [integer1] [integer2]"); System.out.println("T..

if...else... 조건문 사용 예제 for Lua

소스 파일명: testIf.lua --[[ Filename: testIf.lua Purpose: Example using the conditional control structure syntax if .... else ... Execute: lua testIf.lua [number] --]] -- 사용법을 보여주는 함수 function printUsing() print("Using: ruby testIf.rb [number]") print("This determines whether the number is positive or not.") end -- 명령행 인자의 개수가 1이 아니면 사용법을 보여준다. if #arg ~= 1 then printUsing() os.exit(1) end -- 명령행 인자..

프로그래밍/Lua 2008.02.19

if...else... 조건문 사용 예제 for C++

소스 파일명: testIfCPP.cpp #include #include // atof() 함수 사용을 위해 using namespace std; // cout 사용을 위해 // 사용법 표시 함수 void printUsing() { cout ch testCPP.cpp 2.7 2.7000 is a positive number. 실행> ch testCPP.cpp -2.7 -2.7000 is a negative number. 실행> ch testCPP.cpp 0 0 is zero. 이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.

프로그래밍/C++ 2008.02.19