블로그 이미지
송시혁

calendar

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

Notice

Tag

Recent Post

Recent Comment

Recent Trackback

Archive


절대값이 큰 수 구하기

#include <stdio.h>
int abs_max (int n1, int n2);

int main()
{
  int a;
  int b;
  int c;
  
  a= 7;
  b= -8;
  
  c = abs_max(a,b);
  printf("The bigger in absolute value of %d and %d is %d.\n", a, b, c);
  return 0;
}


int abs_max (int n1, int n2)
{
  if(n1 < 0)
  {
    n1 = n1 * -1;
  }
  if(n2 <0)
  {
    n2 = n2 * -1;
  }
  if(n1 >= n2)
  {
    return (n1);  
  }
  else 
  {
    return (n2);
  }
}



숫자 바꾸기





#include <stdio.h>
void swap(int *x, int *y);

int main()
{
  int x;
  int y;
  
  x= 7;
  y =9;
  printf("A: initial vlaue x = %d, y= %d\n", x, y);
  printf("B: &= %08x, &= %08x\n\n"&x, &y);
  
  swap(&x, &y);
  printf(" 바꾼수 x =%d y= %d\n", x, y);


  return 0;
}



void swap(int *px, int *py)
{
  int temp;
  printf("C: px = %08x, py= %08x\n", px, py);
  printf("D: *px = %d, *py = %d\n\n", *px, *py);// *px =7, *py = 9
  
  temp = *px;
  *px = *py;
  *py = temp;
  
  printf("E: px = %08x, py= %08x\n", px, py);
  printf("F: *px = %08x, *py= %08x\n", px, py);
    
    
  
}    




'C언어 수업정리 > 3월 수업정리' 카테고리의 다른 글

3월 29일 리눅스 man 사용법  (0) 2013.03.29
헤더 파일 나누기  (0) 2013.03.28
3월 28일 재귀함수  (0) 2013.03.28
3월 28일 포인터(주소전달)와 함수  (0) 2013.03.28
3월 28일 6-4.c예제  (0) 2013.03.28
posted by 송시혁