연습문제 1
[uzi@uzi pg]$ cat ex23_1.c
#include <stdio.h>
struct simple{
int data1;
int data2;
};
void swap(struct simple *a, struct simple *b);
void show(struct simple k);
int main()
{
struct simple i={1,2};
struct simple j={3,4};
show(i);
show(j);
swap(&i,&j);
show(i);
show(j);
return 0;
}
void swap(struct simple *a, struct simple *b)
{
struct simple *temp;
*temp=*a;
*a=*b;
*b=*temp;
}
void show(struct simple k)
{
printf("%d %d \n",k.data1,k.data2);
}
[uzi@uzi pg]$ ./ex23_1
1 2
3 4
3 4
1 2
[uzi@uzi pg]$
연습문제 2
[uzi@uzi pg]$ cat ex21_1_2.c
#include <stdio.h>
struct point{
int x;
int y;
};
struct point PointAdd(struct point i, struct point j);
struct point getdata(void);
int main()
{
struct point a=getdata();
struct point b=getdata();
struct point c=PointAdd(a,b);
printf("data1: %d , data2: %d\n",c.x,c.y);
return 0;
}
struct point PointAdd(struct point i, struct point j)
{
struct point c;
c.x=i.x+j.x;
c.y=i.y+j.y;
return c;
}
struct point getdata(void)
{
struct point d;
scanf("%d %d",&d.x,&d.y);
return d;
}
[uzi@uzi pg]$ ./ex21_1_2
4 6
5 4
data1: 9 , data2: 10
[uzi@uzi pg]$
'프로그래밍 언어공부 > 열혈강의 C프로그래밍 (2003년작)' 카테고리의 다른 글
열혈강의 C 연습문제 22-1 (0) | 2015.07.15 |
---|---|
열혈강의 C 연습문제 21-2 (0) | 2015.06.30 |
열혈강의 C 프로그래밍 도전 프로그래밍 three 도전 6 (0) | 2013.10.24 |
열혈강의 C 프로그래밍 도전 프로그래밍 three 도전 5 (0) | 2013.10.23 |
열혈강의 C 프로그래밍 도전 프로그래밍 three 도전 4 (0) | 2013.10.23 |