#include <stdio.h>

void PrintHexaNAscii(const unsigned char *buffer, int size);

int main()
{
  int a = 0xffffffff;
  PrintHexaNAscii((unsigned char *)&a, 100);
  return 0;
}

void PrintHexaNAscii(const unsigned char *buffer, int size)
{
  int count1;
  int count2;
  const unsigned char *temp=buffer;
  
  printf(" Address   ");        
  for(count1=0; count1<16; count1++)
  {// 메뉴 구분
    printf("%02X ", count1);    
  }                  
  for(count1=0; count1<16; count1++)  
  {                  
    printf("%01X", count1);      
  }                  
  printf("\n");            

  for(count1=0; count1<=size; count1+=16)
  {// 메뉴 주소
    printf("%#X ", buffer);
    for(count2=0; count2<16; count2++)
    {// 번지 주소
      printf("%02X ", *buffer);
      buffer++;
    }
    
    for(count2=0; count2<16; count2++)
    {// 문자 판별65~90 97~122
      printf("%c", ((*temp>=48)&&(*temp<=57)||
              (*temp>=65)&&(*temp<=90)||
              (*temp>=97)&&(*temp<=122)? *temp : '.'));
      temp++;
    }
    printf("\n");
  }
  printf("\n");
  return;
}

위의 그림과 같이 1부터 순서대로 수를 적어 넣는 달팽이 배열이다.
#include <stdio.h>

int main()
{
  int start=0;
  int count=0;
  int count2;
  int X=0;
  int Y=0;
  int XH;
  int YH;
  int XL=0;
  int YL=0;
  int area[10][10]={0};
  int height;
  int width;
  
  printf("X, Y좌표를 입력하시오 : ");
  scanf("%d %d"&height, &width);
  XH = height-1;
  YH = width-1;

  for(count=0; height*width>count; count++)
  {
    area[Y][X]=count+1;
    
    switch(start)
    {
      case 0 : X++;
           if(XH==X)
           {
             start=1;
             YL++;
           }
           break;
      case 1 : Y++;
           if(YH==Y)
           {
             start=2;
             XH--;
           }
           break;
      case 2 : X--;
           if(XL==X)
           {
             start=3;
             YH--;
           }
           break;
      case 3 : Y--;
           if(YL==Y)
           {
             start=0;
             XL++;
           }
           break;
    }
  }
  
  for(count=0; count<width; count++)
  {
    for(count2=0; count2<height; count2++)
    {
      printf("%2d ", area[count][count2]);
    }
    printf("\n");
  }
  
  return 0;
}

/* 로또 번호 생성 프로그램 */
#include <stdio.h>
#include <stdlib.h>

int main()
{
  unsigned int a[5];
  int cnt;
  int cnt1;
  int count;

  srand((unsigned)time(NULL));  

  printf("*** Lotto Number Generator ***\n");
  printf("==============================\n");
  printf("Enter the game count : ");
  scanf("%d"&count);

  for(; 0<count; count--)
  {
    printf("로또 번호 : ");
    for(cnt=0; cnt<5; cnt++)
    {
      a[cnt]=(rand()%45)+1;
    }
    for(cnt=0; cnt<5; cnt++)
    {
      for(cnt1=0; cnt1<5; cnt1++)
      {
        while(a[cnt]==a[cnt1]&&cnt!=cnt1)
        {
          a[cnt]=(rand()%45)+1;
        }
      }
    }
    for(cnt=0; cnt<5; cnt++)
    {
      printf("%u ", a[cnt]);
    }
    printf("\n");
  }
  printf("==============================\n");
  return 0;
}

1~45번까지의 수를 중복숫자 없이 5가지 출력하는 로또 게임 프로그램이다.


#include <stdio.h>

int main()
{
  int iTemp;
  int iHalf;
  int iCnt;
  
  printf("2 ");

  for(iTemp = 3500 >= iTemp; iTemp+=2// 홀수
  {
    iHalf = iTemp/2;
    iCnt = 3;
    while(iCnt <= iHalf)  // 소수검색
    {
      if(0 == (iTemp%iCnt))
      {
        break;  // while문 브레이크
      }
      iCnt += 2;
    }
    if(iCnt < iHalf)
    {
      continue;  // for문 소속 수행
    }
    printf("%d ", iTemp);
  }
  putchar('\n');
  
  return 0;
}
2~500까지의 소수만을 출력해준다. for문의 500을 원하는 수로 고치면 그 수의 소수를 출력

#include <stdio.h>

int main()
{
  int itemp;
  int ifirst;
  int iend;

  printf("first number input : ");
  scanf("%d"&ifirst);
  printf("End number input : ");
  scanf("%d"&iend);

  for(ifirst; iend>=ifirst; ifirst++)
  {
    for(itemp=1; itemp<=9; ++itemp)
    {
      printf("%d X %d = %d\n", ifirst, itemp, ifirst*itemp);
    }
  }
  return 0;
}
first에 2입력 end에 5입력시 출력값은 2~5까지의 구구단을 출력해준다. (여러 단 동시출력)

+ Recent posts