반응형

* Dot Matrix

 

1. 하트를 그리고, 그 하트를 방향키를 이용하여 움직인다.

 

2. 불켜기 게임을 Dotmatrix로 구현한다. 25개를 다 켜면 HLED가 ON/OFF

 

3. 폭탄 피하기 게임

 

* Key Matrix

 

1. 핸드폰 영문자판 흉내내기

 - 키매트릭스를 핸드폰 자판이라 생각하고 LCD에 글을 써보자

 

* HLED 녹화하기

 - 타이머 인터럽트를 이용해서 구현하기

 

 

 

** 고난도 프로젝트

 

LCD에 Key입력을 받아 명령을 수행한다.

 

MTR RI 30 모터를 오른쪽으로 30도 이동 

MTR LE 15 모터를 왼쪽으로 15도 이동

 

...

반응형
반응형

/* 출력결과

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

*/

 

#include "stdafx.h"
#include <stdio.h>

 

int main()
{

 int a[5][5] = { 0 };
 int cnt = 1;

 for (int i = 1; i < 6; i++) {
  for (int j = 1; j < 6; j++) {
   a[i-1][j-1] = cnt++;
   printf("%3d", a[i - 1][j - 1]);
   }
  printf("\n");
 }

 


 return 0;
}

****************************************************************************************************************************************

 

 

/*

1 1 1 1 1

2 2 2 2 2

3 3 3 3 3

4 4 4 4 4

5 5 5 5 5

*/


#include "stdafx.h"
#include <stdio.h>


int main()
{
 int a[5][5] = { 0 };
 
 for (int i = 1; i < 6; i++) {
   for (int j = 1; j < 6; j++) {
    a[i - 1][j - 1] = i;
    printf("%d ", a[i - 1][j - 1]);
   }
   printf("\n");
 }
 
   
 
    return 0;
}

 

****************************************************************************************************************************************

 

 

 

/*

1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

*/


#include "stdafx.h"
#include <stdio.h>


int main()
{
 
 int a[5][5] = { 0 };
 
 for (int i = 1; i < 6; i++) {
  for (int j = 1; j < 6; j++) {
   a[i-1][j-1] = j;
   printf("%d ", a[i-1][j-1]);
  }
  printf("\n");
 }

 
   
 
    return 0;
}

 

 

****************************************************************************************************************************************

 

/*

1 2 3 4 5

10 9 8 7 6

11 12 13 14 15

20 19 18 17 16

21 22 23 24 25

*/


#include "stdafx.h"
#include <stdio.h>

 

int main()
{
 int a[5][5] = { 0 };
 int cnt = 1;

 for (int i = 1; i < 6; i++) {
  for (int j = 1; j < 6; j++) {
   a[i - 1][j - 1] = cnt++;
   
  }
  
 }


 for (int i = 1; i < 6; i++) {
  if (i % 2 == 1) {
   for (int j = 1; j < 6; j++) {
    

     printf("%3d", a[i - 1][j - 1]);
    }
    
   }
  else
   for (int j = 5; j > 0; j--) {

 

    printf("%3d", a[i - 1][j - 1]);
   }
 
  printf("\n");
 }

 return 0;
}

****************************************************************************************************************************************

 

/*

1 2 3 4 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 12 11 10 9

*/

 

 

#include "stdafx.h"
#include <stdio.h>

 

int main()
{
 int a[5][5] = { 0 };
 int cnt = 0;
 int x = 0, y = 0, dir = 0;

 //dir : 0오른쪽 1아래 2왼쪽 3 위
 while (cnt < 26) {
  cnt++;
  a[y][x] = cnt;

  if (dir == 0) {
   if (a[y][x + 1] == 0 && x < 4)
    x++; 
   else
    dir++;
  }

  if (dir == 1) {
   if (a[y + 1][x] == 0 && y < 4)
    y++;
   else
    dir++;
  }

  if (dir == 2) {
   if (a[y][x - 1] == 0 && x > 0)
    x--;
   else
    dir++;
  }

  if (dir == 3) {
   if (a[y - 1][x] == 0 && y > 0)
    y--;
   else {
    dir = 0;
    x++;
   }
  }
 }


 for (int i = 1; i < 6; i++) {
  for (int j = 1; j < 6; j++) {
   printf("%3d", a[i-1][j-1]);
  }
  printf("\n");
 }
  return 0;
 
}

 

 

반응형

'Study > C' 카테고리의 다른 글

C언어 - 배열 (LED 켜기 게임)  (0) 2018.08.27
C언어 - 배열 (빙고판 만들기)  (0) 2018.08.24
C언어 - 배열 (로또번호 난수발생기)  (0) 2018.08.24
C언어 과제1  (0) 2018.08.21
C언어 과제2  (0) 2018.08.21
반응형

** 배열 사용하여 로또번호 6개 뽑기 **

 


#include "stdafx.h"
#include <stdio.h>
#include <random>
using namespace std;

 

//로또번호 생성기


int main()
{
 random_device rn;
 mt19937_64 rnd(rn());
 uniform_int_distribution<int> range(1, 45);

// 랜덤수 출력 함수

 


 int a[45] = { 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 };
 int tmp=0;
 
 int ran1 = 0;
 int ran2 = 0;

 

 for (int i = 0; i < 100000; i++) {
  
  ran1 = range(rnd);
  ran2 = range(rnd);
  
  tmp = a[ran1-1];
  a[ran1-1] = a[ran2-1];
  a[ran2-1] = tmp;
  
 } // 카드를 2장뽑아서 섞는다.
 
 for (int j = 0; j < 6; j++) {
  printf("%d ", a[j]);
 } // 배열의 1~6까지 출력

 

    return 0;
}

 

********************************************************************************************************************************************

 

** 로또 번호 출력하여 10장 뽑기 **


#include "stdafx.h"
#include <stdio.h>
#include <random>
using namespace std;

//로또번호 생성기
int main()
{
 random_device rn;
 mt19937_64 rnd(rn());
 uniform_int_distribution<int> range(1, 45);
 int a[45] = { 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 };
 int tmp=0;
 
 int ran1 = 0;
 int ran2 = 0;
 for (int k = 0; k < 10; k++) {
  for (int i = 0; i < 100000; i++) {

   ran1 = range(rnd);
   ran2 = range(rnd);

   tmp = a[ran1 - 1];
   a[ran1 - 1] = a[ran2 - 1];
   a[ran2 - 1] = tmp;

  }

  for (int j = 0; j < 6; j++) {
   if (0 < a[j] && a[j] < 10) {
    printf("  %d", a[j]);
   }
   else
    printf(" %d", a[j]);
  }
  printf("\n");
 }
    return 0;
}

 

********************************************************************************************************************************************

 

 

**  로또번호 생성기 OMR 마킹 방식  **

 


#include "stdafx.h"
#include <stdio.h>
#include <random>
using namespace std;

//로또번호 생성기 OMR 마킹 방식
int main()
{
 random_device rn;
 mt19937_64 rnd(rn());
 uniform_int_distribution<int> range(1, 45);
 
 int a[45];

 


 int ran1 = 0;
 int cnt = 0;

 for (int i = 0; i < 11; i++) {
  for (int q = 0; q < 45; q++)
  {
   a[q] = q + 1;
  }
  while (cnt < 6) {

   ran1 = range(rnd);
   if (a[ran1 - 1] != 0) {
    printf("%3d ", a[ran1 - 1]);
    a[ran1 - 1] = 0;
    cnt++;
   }

  }
  printf("\n");
  cnt = 0;
 }
   
   
 
    return 0;
}

 

********************************************************************************************************************************************

 

 

반응형

'Study > C' 카테고리의 다른 글

C언어 - 배열 (빙고판 만들기)  (0) 2018.08.24
C언어 - 배열 (2차원배열)  (0) 2018.08.24
C언어 과제1  (0) 2018.08.21
C언어 과제2  (0) 2018.08.21
연산자의 활용  (0) 2016.02.26

+ Recent posts