#include <stdio.h>
#include <stdlib.h>

#define   LEN  16

int main(int iParam, char *cpParam[])
{
  int   iCnt=0;
  int   iCnt2=0;
  FILE  *stFile;
  char  cBuf;
  char  caStr[LEN+1]="";  // NULL초기화 17개 

  if(2 != iParam)
  {  // 인자 검사 2개가 아니면 종료!
    fprintf(stdout, "파일 이름을 쓰세요\n");
    return 0;
  }

  stFile = fopen(cpParam[1], "rb");  // 2진모드로 읽기!
  if(0 == stFile)
  {  // 못열경우 실행!!
    fprintf(stdout, "[%s]파일을 찾을 수 없습니다\n", cpParam[1]);
    return 0;
  }
  printf("┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓\n");
  printf("┃  ADDR  ┃00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ┃0123456789ABCDEF┃\n");
  printf("┣━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━┫\n");

  while((cBuf=fgetc(stFile)) != EOF)
  {  // 헥사 뷰 시작~~~ 32이하는 .으로 표시!
    if(0 == iCnt)
    {
      printf("┃%08X┃", iCnt2++);
    }
    printf("%02X ", (unsigned char)cBuf);
    if(cBuf <= 31)
    {
      caStr[iCnt++]='.';
    }
    else
    {
      caStr[iCnt++]=cBuf;
    }
    if(iCnt >= LEN)
    {
      caStr[iCnt]='\0';
      printf("┃%s┃\n", caStr);
      iCnt=0;
    }
  }
  if((0<iCnt)&&(16>=iCnt))
  {
    while(LEN>iCnt)
    {
      printf("   ");
      caStr[iCnt++]=' ';
    }
  printf("┃%s┃", caStr);
  }
  printf("\n┗━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━┛\n"); 

  fclose(stFile);
  return 0;
}

'C언어 > 과제' 카테고리의 다른 글

C언어 과제 11  (0) 2010.10.27
C언어 과제 10  (0) 2010.10.27
C언어 과제 09  (0) 2010.10.25
C언어 과제 08  (0) 2010.10.25
C언어 도전과제 01 (소수와 합성수를 판단하여라)  (0) 2010.10.20

1. 두 개의 정수를 입력받고 두 정수 사이에 5의 배수의 개수를 출력하는 프로그램을 작성하세요.

출력)    정수(2) 입력 : 5 21

           출력 : 3

//정수 2 입력하면  정수 사이의 5 배수갯수 출력!!
#include <stdio.h>

int multiple(int a, int b);

int main()
{
  
int inum1;
  
int inum2;

  fprintf(stdout, 
"정수 2개를 입력 : ");
  fscanf(stdin, 
"%d %d"&inum1, &inum2);
  
  fprintf(stdout, 
"\n출력 : %d\n", multiple(inum1, inum2));
  
return 0;
}

int multiple(int a, int b)
{
  
int multi=0;
  
int count;
  
  
for(count=a+1; count<b; count++)
  {
    a
=count%5;
    
if(a==0)
    {
      multi++;
    }
  }
  
return multi;
}

 

 

2. 두 개의 정수를 입력받고 두 정수 사이의 부호를 다음과 같이 바꿔가면서 계산한 식과 결과를 출력하세요.

출력)    정수(2) 입력 : 1 10

           X = 1 – 2 + 3 – 4 + 5 – 6 + 7 – 8 + 9 – 10

           X = -5

//두개의 정수를 입력받아 부호를 바꿔가며 계산하기!!
#include <stdio.h>

int sum(int a, int b);

int main()
{
  int inum1;
  int inum2;
  int count;
  int count1;

  fprintf(stdout, "
정수 2개를 입력 : ");
  fscanf(stdin, "%d %d"&inum1, &inum2);
  
  fprintf(stdout, "X = ");
  for(count=inum1; count<=inum2; count+=2)
  {
    fprintf(stdout, "%d", count);
    for(count1=0; (1>count1)&&(count<inum2); count1++)
    {
    fprintf(stdout, " - ");
      fprintf(stdout, "%d", count+1);
      if(count+1!=inum2)
      {
        fprintf(stdout, " + ");
      }
    }
  }
  fprintf(stdout, "\n");
  
  fprintf(stdout, "
출력 : %d", sum(inum1, inum2));
  return 0;
}

int sum(int a, int b)
{
  int count;
  int add=0;
  int sub=0;
  int sum=0;

  for(count=a; count<=b; count+=2)
  {
    add+=count;
  }
  for(count=a+1; count<=b; count+=2)
  {
    sub+=count;
  }
  sum=add-sub;
  return sum;
}

 

 

 

3. 사용자에게 년도를 입력 받아 윤년인지 아닌지를 판단하는 판단하는 프로그램을 작성하시오.

윤년은 아래와 같다.

l  4로 나누어 떨어지는 해이다.

l  그 중에서 100으로 나누어 떨어지는 해는 평년

l  다만 400으로 나누어 떨어지는 해는 다시 윤년

출력)    Input Year :  2000

           [2000] is leap year

           Input Year :  2001

           [2001] is common year

 

//년도 입력시 윤년 or 평년 출력
#include <stdio.h>

int Year(int a);

int main()
{
  int year;
  int count;
  int inum;

  fprintf(stdout, "
확인하고 싶은 년도 입력 : ");
  fscanf(stdin, "%d"&year);

  if(Year(year)==0)
  {
  fprintf(stdout, "%d
년도는 윤년 입니다. \n", year);
  }
  else
  {
  fprintf(stdout, "%d
년도는 평년 입니다. \n", year);
  }
  return 0;
}

int Year(int a)
{
  int year;
  
  year=a%4;
  if(0==year)
  {
    if(0==(year=a%100))
    {
      if(0==(year=a%400))
      {
        return 0;
      }
      return 1;
    }
    return 0;
  }
  else
  {
    return 1// 

  }
}

 

 

4. 입력한 문자가 소문자이면 대문자로, 대문자이면 소문자로 변경하는 함수를 구현하세요. 문자 ch를 입력 받고, ch가 소문자이면 대문자로 출력합니다.

출력)    문자 : a97

           대문자로 변환 : A65

 

           문자 : C

           소문자로 변환 : c

 

//문자 입력시  문자 바꿔주기
#include <stdio.h>

char change(char a);

int main()
{
  
char ch;

  fprintf(stdout, 
"문자를 입력해주세요 : ");
  fscanf(stdin, 
"%c"&ch);

  
if(change(ch)=='a')
  {
    fprintf(stdout, 
"소문자를 대문자로 변환 : %c\n", ch-=32);
  }
  
else
  {
    fprintf(stdout, 
"대문자를 소문자로 변환 : %c\n", ch+=32);
  }
  
return 0;
}

char change(char a)
{

  
if((a>='A')&&(a<='Z'))
  {
    
    
return ;
  }
  
else
  {
    
return 'a';
  }
}


'C언어 > 과제' 카테고리의 다른 글

불러온 파일 Hexacode 보여주기  (0) 2010.12.09
C언어 과제 10  (0) 2010.10.27
C언어 과제 09  (0) 2010.10.25
C언어 과제 08  (0) 2010.10.25
C언어 도전과제 01 (소수와 합성수를 판단하여라)  (0) 2010.10.20

1. 잘못된 부분을 찾아서 고치고, 이유를 설명하세요.

1)  int num = 128;

    char* pNum = &num;

    printf(“%d”, *pNum);

 

  int num = 128;

    unsigned char* pNum = (unsigned char*)&num;

    printf(“%d”, *pNum);

    num int형변수이기 때문에 캐스팅을 해주기위해 (unsigned char*)를 입력해준다.

    int형은 128(4byte) char(2byte)에 대입시켜주면 -128이 되기 때문에 정수형으로 바꿔주기위해

    포인트변수앞에 unsigned를 입력해준다.

 

2)  char* pStr = “Control”;

    printf(“%s \n”, *pStr);

 

 

 

 

2. char형 변수 ch1 ch2의 데이터를 서로 바꾸는 swap함수를 구현하세요. 변수 ch1에는 ‘A’, 변수 ch2에는 ‘C’가 대입되어 있습니다. Call By Reference(참조에 의한 호출)로 함수를 호출하세요.

출력)    Before : ch1=A, ch2=C

           After  : ch1=C, ch2=A

 

#include <stdio.h>

char swaps(char *a);

int main()
{
  
char ch1,ch2;
  
char *swap;
  
char cnum1,cnum2;
  
  fprintf(stdout, 
"Character Key Input : ");
  fscanf(stdin, 
"%c %c"&ch1, &ch2);
  
  cnum1
=swaps(&ch2);
  cnum2
=swaps(&ch1);
  
  fprintf(stdout, 
"Before : ch1=%c, ch2=%c\n", ch1, ch2);
  fprintf(stdout, 
"After  : ch1=%c, ch2=%c\n", cnum1, cnum2);
  
return 0;
}

char swaps(char *a)
{
  
char *swap;
  swap
=a;
  
return *swap;
}

3. 문자가 숫자인지 알려주는 isdigit 함수를 구현하세요. 문자 ch를 입력 받고, ch가 숫자인지 출력하세요. 맞다면 YES, 아니면 NO를 출력합니다.

출력)    문자 : P

           결과 : NO

 

 

#include <stdio.h>

int main()
{
  
char ch;

  fprintf(stdout, 
"문자나 숫자를 입력하시오 : ");
  fscanf(stdin, 
"%c"&ch);

  
if((65<=ch)&&(122>=ch))
  {
    fprintf(stdout, 
"문자 : %c\n결과 : No", ch);
  }
  
else
  {
    fprintf(stdout, 
"숫자 : %d\n결과 : Yes", ch-48);
  }  
  
return 0;
}


'C언어 > 과제' 카테고리의 다른 글

불러온 파일 Hexacode 보여주기  (0) 2010.12.09
C언어 과제 11  (0) 2010.10.27
C언어 과제 09  (0) 2010.10.25
C언어 과제 08  (0) 2010.10.25
C언어 도전과제 01 (소수와 합성수를 판단하여라)  (0) 2010.10.20

 1. 10진수 0부터 16까지의 정수를 8진수로 출력합니다출력에는 10진수와 8진수의 대응관계를 반드시 포함시킵니다. printf함수의 %o플래그를 사용할 수 없습니다.

출력)  10진수  8진수

-------------------

            0        0

            1        1

            2        2

            3        3

            4        4

            5        5

            6        6

            7        7

            8        10

            9        11

           10       12

           11       13

           12       14

           13       15

           14       16

           15       17

           16       20

#include <stdio.h>

int main()
{
  
int dec=0;
  
int oct=0;
  
int count;
  
int mok;
  
int nmg;
  
  fprintf(stdout, 
"10진수\t8진수\n");
  fprintf(stdout, 
"=============\n");
  
  
for(count=016>=count; count++)
  {
    mok
=count/8;
    nmg
=count-(mok*8);
    oct
=(mok*10)+nmg;
    fprintf(stdout, 
"  %2d\t %2d\n", dec++, oct);
  }
  
return 0;
}

 

2. 정수의 자릿수를 구하세요.

출력)    정수 입력 : 325

           자릿수   : 3

 

정수 입력 : 4589

           자릿수   : 4

 

정수 입력 : -1

           프로그램 종료!

#include <stdio.h>

int main()
{

  
int inum;
  
int inum2;
  
int cnt;
  
  
while(1)
  {
    fprintf(stdout, 
"정수를 입력 : ");
    fscanf(stdin, 
"%d"&inum);
    inum2
=inum;
    
if(0!=inum2)
    {
      
for(cnt=01<inum; cnt++)
      {
        inum/
=10;
      }
    }
    
else
    {
      fprintf(stdout, 
"0입력하지말고 다시 입력해!!\n");
      
continue;
    }
    
if(-1==inum2)
    {
      fprintf(stdout, 
"프로그램 종료!\n");
      
break;
    }
    fprintf(stdout, 
"정수\t: %d\n", inum2);
    fprintf(stdout, 
"자릿수\t: %d\n", cnt);
  }
  
return 0;
}

 

3. 1바이트는 8개의 비트로 이루어집니다. 255 8개 비트 전체가 1인 경우이고, 1은 최하위 비트만 1인 경우입니다문자 ch의 켜진 비트 개수는 몇 개입니까켜진 비트는 1로 설정된 비트의 다른 표현입니다.

대문자 ‘A’의 값은 65이고 6번째와 1번째 비트가 켜져 있습니다.

출력)    문자 입력 : A

           켜진 비트의 개수 : 2

            : 65

 

#include <stdio.h>

int main()
{
  
char ch;
  
int count;
  
int iNum,iNum2=1;
  
int bit=0;

  fprintf(stdout, 
"문자를 입력하세요 : ");
  fscanf(stdin, 
"%c"&ch);
    
for(count=18>=count; count++)  // 켜진 비트 검출문
      {
        iNum
=(iNum2&ch)/(iNum2);// 0~7번비트 켜져있나 확인
        
if(iNum==1)        // 켜진경우 실행
        {
          bit++;        
// 비트 카운터
        }
        iNum2
=1<<count;      // 0~7번비트까지 쉬프트
      }
  fprintf(stdout, 
"켜진 비트의 갯수: %d\n", bit);
  fprintf(stdout, 
"입력된 문자 \t: %d\n", ch);
  
return 0;
}

'C언어 > 과제' 카테고리의 다른 글

C언어 과제 11  (0) 2010.10.27
C언어 과제 10  (0) 2010.10.27
C언어 과제 08  (0) 2010.10.25
C언어 도전과제 01 (소수와 합성수를 판단하여라)  (0) 2010.10.20
C언어 과제 07  (0) 2010.10.14

1. 난수를 발생하는 rand 함수를 활용하여 주사위를 10번 던졌을 때 주사위 값을 출력하시오.

(주사위 값 : 1~6)

출력)    dice value :  5

           dice value :  2

           dice value :  1

           ...

           dice value :  1

#include <stdio.h>

int main()
{
  int cnt;
  
  srand((unsigned)time(NULL));
  
  for(cnt=06>cnt; cnt++)
  {
  printf("dice value : %d\n", (rand()%6)+1);
  }
  return 0;
}

 

 

2. 초 입력시 분과 초로 변환하는 프로그램을 작성하세요.

출력)    Input Seconds :  100

           Output :  1 min 40 sec

 

#include <stdio.h>

int main()
{
  
int time;
  
int min=0;
  
  printf(
"Input Seconds : ");
  scanf(
"%d"&time);

  
while(60<=time)
  {
    time
=time-60;
    min++;
  }
  printf(
"Output : %dmin %dsec", min, time);
  
return 0;
}


3. 1바이트 범위의 정수를 입력 받은 다음, 각각의 비트가 켜져 있으면 1, 꺼져 있으면 0을 출력하세요.

출력)    정수 입력(0~255) : 127

 

           비트     스위치

           ------------------

           0   :     1

           1   :     1

           2   :     1

           3   :     1

           4   :     1

           5   :     1

           6   :     1

           7   :     0

           ------------------

//정수 입력시 켜진 비트자리 표시
#include <stdio.h>

int main()
{
  
int inum;
  
int count;
  
int bit;
  
int swit=1;

  fprintf(stdout, 
"정수 0~255 입력 : ");
  fscanf(stdin, 
"%d"&inum);
  fprintf(stdout, 
"비트\t스위치\n");
  fprintf(stdout, 
"==============\n");
  
for(count=18>=count; count++)
  {
    bit
=(swit&inum)/swit;
    fprintf(stdout, 
"  %d   :   %d\n", count-1, bit);
    swit
=1<<count;
  }

  
return 0;
}

4. 수직 막대 그래프(histogram)와 관련된 문제입니다. 정수 N1, N2, N3의 길이를 갖는 막대 그래프를 출력하세요(0 < N1, N2, N3 < 10,  막대문자 : *).

출력)    정수(3) 입력 : 7 2 5

           7   2   5

       --------------

           *   *    *

           *   *    *

           *        *

           *       *

           *       *

           *

           *

#include <stdio.h>

int main()
{
  
int inum, inum1, inum2;
  
int max;
  
int count;
    
  fprintf(stdout, 
"정수(3입력 : ");
  fscanf(stdin, 
"%d %d %d"&inum, &inum1, &inum2);

  fprintf(stdout, 
"%d  %d  %d\n=======\n", inum, inum1, inum2);
  
if(inum>inum1)
  {
    max
=inum;
  }
  
else
  {
    max
=inum1;
  }
  
if(max<inum2)
  {
    max
=inum2;
  }
  
  
for(count=0; count<max; count++)
  {
    
if((0<inum)&&(max>=inum))
    {
      fprintf(stdout, 
"*");
    }
    
else
    {
      fprintf(stdout, 
" ");
    }
    
if((0<inum1)&&(max>=inum1))
    {
      fprintf(stdout, 
"  *");
    }
    
else
    {
      fprintf(stdout, 
"   ");
    }
    
if((0<inum2)&&(max>=inum2))
    {
      fprintf(stdout, 
"  *");
    }
    fprintf(stdout, 
"\n");
    inum--;

    inum1--;

    inum2--;
  }
  
return 0;
}


'C언어 > 과제' 카테고리의 다른 글

C언어 과제 10  (0) 2010.10.27
C언어 과제 09  (0) 2010.10.25
C언어 도전과제 01 (소수와 합성수를 판단하여라)  (0) 2010.10.20
C언어 과제 07  (0) 2010.10.14
C언어 과제 06  (0) 2010.10.14

+ Recent posts