U E D R , A S I H C RSS

구구단/Leonardong

데블스캠프 첫째날 구구단 코드


C++ 처음 짠 코드
~cpp 
#include <iostream>
using namespace std;

int main()
{
	for (int by=1 ; by<10 ; by++)
	{
		for (int i=2 ; i<6 ; i++)
			cout << i << " * " << by << " = " << i*by << "\t";
		cout << endl;
	}
	cout << endl;
	for (by=1 ; by<10 ; by++)
	{
		for (int i=6 ; i<10 ; i++)
			cout << i << " * " << by << " = " << i*by << "\t";
		cout << endl;
	}

	return 0;
}

데블스캠프 셋째날 구구단 코드


Scheme 첫번째 방법 - when
~cpp 
(define (niner by plus) (when (< by 10)
                          (cond ((< plus 10) (begin (print by) (print *) (print plus) (print =) (print (* by plus)) (newline) (niner by (+ plus 1))))
                                ((>= plus 10) (niner (+ by 1) 1))
        )))                                  
(niner 2 1)

Scheme 두번째 방법 - if
~cpp 
(define (niner by plus) 
  (if (< by 10)
      (cond ((< plus 10) (begin (print by) (print *) (print plus) (print =) (print (* by plus)) (newline) (niner by (+ plus 1))))
            ((>= plus 10) (niner (+ by 1) 1))
        ) (print "end") ))                                  
(niner 2 1)

Squeak 첫번째 방법
  • Niner 클래스

~cpp 
Object subclass: #NameOfSubclass
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Leonardong'
  • Niner2to9 메소드

~cpp 
Niner2to9
	| gob pp |
	gob:=2.
	pp:=1.
	8 timesRepeat:
		[9 timesRepeat:
			[Transcript show: gob*pp;cr.
			 pp := pp + 1.].
		 gob := gob + 1.
		 pp := 1].	
  • workspace

~cpp 
niner := Niner new.
niner Niner2to9.


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0085 sec