| 태그 '클리닉'에 해당되는 글 1건 |
| C클리닉 특강용 소스 #2 |
Tech - https://ohyung.net/363 (YMD: 07/03/04 17:57)
본 소스는 2007년 2월 21일부터 시행되었던 손채봉 교수님의 C클리닉 유인물 2번째 장을 약간 풀어본것입니다.

본소스는 모두 주석처리 되어있습니다 -.-;
주석 푸는 법은 알아서 */ 만 붙이시면 됩니다.
Code Type : C
/////////////////////////////////////////
//  2007년 03월 04일 고급프로그래밍  //
// Coded By 오형탁 Ohyung (2002711158) //
// ohyung@ohyung.com http://ohyung.com //
/////////////////////////////////////////

/* 입력하기 귀찮아!
#include< stdio.h>
void main()
{
}
/**/

/* 출력값 - 4 -12 , 4들어감 근데 b가 4이므로 f()다시 4,0이됨 - 0은 없으므로 a에 입력된 4가 리턴된후 출력 
#include< stdio.h>
int f(int a,int b)
{
    return b ?f(b,a%b):a;
}
void main()
{
    printf("%d\n",f(12,4));
}
/**/

/* 결과값 - 5 -2의 보수로 계산 하면서 날리면 됨.
#include< stdio.h>
void main()
{
    int x=3333,y=-77777;
    printf("%d",x&y);
}
/**/

/* 빈칸체우기 
#include< stdio.h>
int f(int n)
{
    if (n<=1) return(1);
    else return(n*f(n-1));
}
void main()
{
    printf("%d",f(5));
}
/**/

/* y값? - 0,1,5,14,30 - 1부터 5까지 sum_of_p를 함.
#include< stdio.h>
#define A 5
sum_of_p(int n)
{
    int i,sum=0;
    for(i=1;i
void main()
{
    int a,b;
    int c=(a=1)+(b=2);
    printf("%d",c);
}
/**/

/* 출력값 0 0 - c1=0 c2=-1 c3=0 c4=1이 enum으로 정의됨.
#include< stdio.h>
void main()
{
    enum {c1,c2=-1,c3,c4};
    printf("%d %d",c1,c3);
}
/**/

/* 소문to대문 
#include< stdio.h>
void main()
{
    int c=0;
    gets(&c);
    if ('a'<= c && c<= 'z')
        putchar(c+'A'-'a');
}
/**/


/* 알맞은 출력형식 100 3.141592e0 99 로 출력되기 위해서
#include< stdio.h>
void main()
{
    int i=100;
    float f=3.141592;
    char c='c';
    printf("%d %e %d",i,f,c);
}
/**/

/* 형변환 일어나는 횟수 - 3번 - I출력 우선 B->44로 바뀌고 4와 더해진뒤 3.5가 더해지면서 바뀜 그뒤 c로 저장 후 출력할때 한번더 바뀜 
#include< stdio.h>
void main()
{
    char c;
    c='B'+4+3.5;
    printf("%c\n",c);
}
/**/

/* 출력값 - 필터 xor를 생각하면됨! 
#include< stdio.h>
void main()
{
    int a=32;
    int filter=255;
    a=a&filter;
    printf("%d",a);
}
/**/

/* t의 값 20번 실행 5의 배수만큼 실행 ㅎㅎ
#include< stdio.h>
void main()
{
    int i,t=0;
    for(i=1;i<=100;i++)
    {
        if(i%5 !=0) continue;
        t=t+1;
    }
    printf("%d",t);
}
/**/

/* 출력값 0 1 2 3 5 6 
#include< stdio.h>
void main()
{
    int i;
    for(i=0;i<=6;i++)
    {
        if(i==4) continue;
        else printf("%d ",i);
    }
}
/**/

/* 문자읽고 궈궈싱! EOF는 Ctrl + Z와 같음...
#include< stdio.h>
void main()
{
    int c;
    while((c=getchar())!=EOF)
    {
        putchar(c);
    }
}
/**/

/* 출력값 9 8 7 6 5 4 3 2 1 0
#include< stdio.h>
void main()
{
    int a=10;
    do
    {
        a--;
        printf("%d",a);
    }
    while(a>0);
}
/**/

/* 출력값? 2,10 답은에러 "가 첨가되어있었음 -.-;
#include< stdio.h>
void main()
{
    int a=2,b=10;
    if(!a==!b) printf("%d",a),printf(" %d",b);
    // if(!a==!b) printf("%d",a),printf(" %d",b"); //원래 문제;;;
}
/**/

/* 라인갯수 구하기! Ctrl+z로 빠져나오면 됨.
#include< stdio.h>
void main()
{
    int c,cnt;
    cnt=0;
    while ((c=getchar())!=EOF)
        if(c=='\n')++cnt;
    printf("%d\n",cnt);
}
/**/

/* 1~100의 합구하기 
#include< stdio.h>
int add(int i)
{
    return((i==0)?0:i+add(i-1));
}
void main()
{
    int sum=0;
    sum=add(100);
    printf("%d\n",sum);
}
/**/

/* 출력값? char 형은 4Byte이므로 뒤에서 2개가 출력? 뭐였더라.... 암튼 비슷함;; 
#include< stdio.h>
void main()
{
    unsigned char c=0x123456;
    printf("%x\n",c);
}
/**/

/* 출력값? 1234 1235 1235 1233 1234
#include< stdio.h>
#define INC(i) i+1
#define DEC(i) i-1
#define OLD(i) DEC(INC(i))
void main()
{
    int n=1234;
    printf(" %d",n++);
    printf(" %d",n--);
    printf(" %d",INC(n));
    printf(" %d",DEC(n));
    printf(" %d\n",OLD(n));
}
/**/

/* 출력값? - 11
#include< stdio.h>
#define SQ(x) x*x
void main()
{
    printf("%d\n",SQ(2+3));
}
/**/
| 이 포스트에 대한 이용규약 |
Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시 2.0 라이센스 에 따라 이용하실 수 있습니다.
This work is licensed under a Creative Commons Attribution 2.0 Korea LicenseLink in a new window.

| 이 글과 태그로 연관된 글 |

| 트랙백 |
트랙백 주소 :: https://ohyung.net/rserver.php?mode=tb&sl=363