전체 글
-
조합 계산 (재귀함수)코딩/C언어 2019. 3. 18. 18:47
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include int comb(int n, int r) { if (r == 0 || r == n) return 1; else return comb(n - 1, r - 1) + comb(n - 1, r); } int main(void) { int C10_5; C10_5 = comb(10, 5); printf("%d\n", C10_5); return 0; } Colored by Color Scripter cs 결과:
-
제곱 구하기 (재귀함수)코딩/C언어 2019. 3. 18. 18:42
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include int xPower(int x, int y); int main(void) { int x, y; printf("Enter two numbers: "); scanf("%d %d", &x, &y); printf("%d의 %d승은 %d이다.\n", x, y, xPower(x, y)); } int xPower(int x, int y) { if (y == 0) return 1; else return x * xPower(x, y - 1); } Colored by Color Scripter cs 결과:
-
지뢰찾기 (中 폭탄 수 세기)코딩/C언어 2019. 3. 18. 18:38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 #include #include #include #define X_VALUE 5 #define Y_VALUE 5 void readBombInfo(char grid[][Y_VALUE + 1]) { int i; printf("input Grid\n"); for (i = 0; i
-
학생 정보 출력 (추상클래스)코딩/java 2019. 3. 18. 18:17
public abstract class Student { private int id; private int tuition; private double gpa; public void setTuition(int tuition) {this.tuition = tuition;}; public void setGpa(double gpa) {this.gpa = gpa;}; public int getId() {return id;}; public int getTuition() {return tuition;}; public double getGpa() {return gpa;}; public abstract int clacScholarship(); public String toString() {//public 지울 수 있다...
-
객체 비교하기코딩/java 2019. 3. 18. 18:10
public class Student { private int id; private int tuition; private double gpa; private String name; private String major; public void setTuition(int tuition) {this.tuition = tuition;}; public void setGpa(double gpa) {this.gpa = gpa;}; public int getId() {return id;}; public int getTuition() {return tuition;}; public double getGpa() {return gpa;}; public int clacScholarship() { return tuition / ..
-
사각형 넓이 비교코딩/java 2019. 3. 18. 18:04
public class Square { private int width; private int height; public void setWidth(int width) {this.width = width;}; public int getWidth() {return width;}; public void setHeight(int height) {this.height = height;}; public int getHeight() {return height;}; private int area() {return width * height;}; public boolean isSmallarThan(Square s) { if (s.area() > this.area()) { return true; } else { retur..
-
키, 몸무게 비교코딩/java 2019. 3. 18. 17:59
public class BodyData { private int weight; private int height; public void setWeight(int weight) {this.weight = weight;}; public void setHeight(int height) {this.height = height;}; public int getWeight() {return weight;}; public int getHeight() {return height;}; public int idealWeight() { return height - 110; } public boolean isTallerThan(BodyData b) { if (b.getHeight() < height) { return true;..
-
상자의 정보 (함수 재정의)코딩/java 2019. 3. 8. 16:32
public class Box { private int x; private int y; private int z; private boolean empty; public String toString() { String rslt = "가로: " + x + "cm 세로: " + y + "cm 높이: " + z + "cm"; return rslt; } public void fillBox() { this.empty = false; } public void emptyBox() { this.empty = true; } public int getVolume() { return x * y * z; } public double getWeight() { return 1.1 * getVolume(); } public Box(..