U E D R , A S I H C RSS

새싹교실/2012/AClass/4회차

4 로드

  • 드는 {{{ }}} 면 됩다.

곽길문

11.던 내로, int* a; int b; int **c;로 때 &c,c,*c,&a,a 각각 고, 떤 것 떤 것과 는 것 말로 .
- 갖는 것다. 그 따라 &c는 는 것고 c는 a 다. *c또 a 다 . &a는 a 값, a는 a가 b를 가리는 것라면 b 다.

12. 드가 고, 그런 값 다.
int* a;
int b=5;
int** c;
c=&a;
a=&b;
  • *c=9;
    printf("%d %d",*c,**c);
-결과 : 3210468 9
- : int 를 가리로 a, b 5를 , 를 가리는 c를 다. a c 다. b a 다. 그리고 c 9로 다. a 갖고 던 c 9를 대다. 따라 *c,**c를 면 a 9가 된다.


1.5.1.2




2.Circular Queue가 무 .
- 로 기본 가되는 과 끝부 그 데를 가리게 된다. F 끝부 가리는 것 R면 꽉 F가 R 가리는 것 같기 때문 F,R 고 꽉 를 구 다. 따라 는 방법 많겠만 그 나는 배 고 배가 N라면 N-1만 때 꽉 는 방법다. 렇게 나를 낭게 된다. 나가 되는 다.

3.typedef가 무 보고, .
- c는 char,int,float 기본 데 과 배, , 구 된 데로부 만들 는데, 록 typedef 다. typedef #define과 달리 는 c 고 typedef 리되는 것 라 c 리된다. 또 #define보다 다 가능다.

< : typedef 기 ; >

:
#include <stdio.h>
void main()
{
typedef char *YOU;

YOU name ="color";
YOU color = "red, blue, yellow, black";

printf("name=%s \n",name);
printf("color=%s \n",color);

}

결과 :
name =color
color =red, blue, yellow, black

:
typedef문 char를 로 *YOU를 고 YOU name는 char *name로 나낸것과 같다.

4.구 student 구나 만들고, student 구 만들 0~3 AClass 보를 고, 그것 .
내부 char 배 고, int 다.
-.. 러가 뜰까..
#include<stdio.h>

struct Student
{

int age;
char name[];

};

int main()
{
int i;
struct Student stu4={24,"길æ문¹�"},{24,"≫oEn"},{23,"¼UAI"},{22,"Cy림¸²"};



for(i=0;i<4;i++){


printf("age : %d\n name : %s \n",stui.age,stui.name);

}

return 0;
}

-나머 녁까 리겠


8.다 력되는 로그램 .
8 당 문다. 나 다른게 물
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
21 20 19 18 17 16
#include <stdio.h>

int main()
{
	int a[6][6];
	int i,j;
	int count=1;

	for(i=0;i<6;i++)
	{
		if(i%2!=0)
		{
			for(j=i;j>=0;j--)
			{
				a[i][j]=count;
				count++;
			}
		}
		else
		{
			for(j=0;j<=i;j++)
			{
				a[i][j]=count;
				count++;
			}
		}
	}
	for(i=0;i<6;i++)
	{
		for(j=0;j<=i;j++)
		{
			if(a[i][j]<10)
				printf("%d  ",a[i][j]);
			else
				printf("%d ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
} 
9.2 3x3 두개 만들고, 두 배 로그램 .
hint) Dp = (int**)malloc(sizeof(int*));

10.3 10 . 는 반드 다. 모르면 물되고, 다른 드를
//10.LinearSearch를 구. 배 1000개로 고, random 1부 1000까 를 랜덤로 배 , 777 면 됩다.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void random(int a[]);
int main()
{
	int x;
	int a[1000];
	int i;
		
	srand(time(NULL));
	
	for(i=0;i<1000;i++)
	{
		x=1+rand()%1000;
		a[i]=x;
//		printf("%d ",a[i]);
	}
//	printf("\n");
	random(a);
	
	return 0;
}

void random(int a[])
{
	int find[1000]={0};
	int i;

	for(i=0;i<1000;i++)
	{
		if(a[i]==777)
			find[i]=i;	
		
		if(find[i]!=0)
			printf("777 %d 다\n",find[i]);
	}
	
} 
11.던 내로, int* a; int b; int **c;로 때 &c,c,*c,&a,a 각각 고, 떤 것 떤 것과 는 것 말로 .
&c : c
c : c 값(a )
*c : c가르는 곳 값(b )
&a : a
a : a 값(b )
c==&a
*c==a==&b
12. 드가 고, 그런 값 다.
int* a;
int b=5;
int** c;
c=&a; // c a
a=&b; // a b
**c=9; // c 방(?) 9를
printf("%d %d",*c,**c); // *c는 a 가 들고 **c는 b다.


1.5.1.2

LinkedList node를 는 방법 보고, 그런 .
-struct Node{
char Name20;
struct Node *Next;
};
- 데 Name라는 변 노드를 가리 는 Next다.

Circular Queue가 무 .
- 배 기반 .
- 기 때문 가 가득 때나 때 Front Rear index는 동므로 Empty Full 다.

typedef가 무 보고, .
- 기 는 것
typedef struct
{
char *name;
int age;
char sex;
}Student;

student 구나 만들고, student 구 만들 0~3 AClass 보를 고, 그것 .
내부 char 배 고, int 다.
가 무 되는 경 반드 게 물보고, 과다.
#include <stdio.h>

typedef struct 
{
	char *name;
	int age;
	char sex;
	
}Student;
int main()
{
	Student Std[4];
	int i;

	Std[0].name="곽길문";
	Std[0].age=24;
	Std[0].sex='F';
	Std[1].name="";
	Std[1].age=24;
	Std[1].sex='F';
	Std[2].name="";
	Std[2].age=23;
	Std[2].sex='F';
	Std[3].name="림";
	Std[3].age=22;
	Std[3].sex='F';
	

	printf("\t나\t\n");
	for(i=0;i<4;i++)
	{
		printf("%s\t%d\t%c\n",Std[i].name,Std[i].age,Std[i].sex);
	}
	return 0;
} 


1~6. Koistudy.net 106~111
->!


7. Koistudy.net 125, 152(둘다 들면 나만) 3n+1
accept accept는데 나 다른게 물 다^^
-> 못!

8. 다 력되는 로그램 .
8 당 문다. 나 다른게 물
1  
3  2  
4  5  6
10 9  8  7
11 12 13 14 15
21 20 19 18 17 16

#include <stdio.h>
int main(){
	int i,j;
	int arr[6][6]={0,};
	int num=0;

	for(i=0 ; i<6 ; i++){
		if(i%2==0){
			for(j=0 ; j<=i ; j++) arr[i][j]=++num;
		}else{
			for(j=i ; j>=0 ; j--) arr[i][j]=++num;
		}
	}

		for(i=0 ; i<6 ; i++){
			for(j=0 ; j<6 ; j++){
				if(arr[i][j] != 0) printf("%3d",arr[i][j]);
			}
			printf("\n");
		}
	
	return 0;
}


9. 2 3x3 두개 만들고, 두 배 로그램 .
hint) Dp = (int**)malloc(sizeof(int*));
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
	int **p1;
	int **p2;
	int i,j;
	srand(time(NULL));
	p1=(int**)malloc(sizeof(int*)*3);
	p2=(int**)malloc(sizeof(int*)*3);
	for(i=0 ; i<3 ; i++){
		p1[i]=(int*)malloc(sizeof(int*)*3);
		p2[i]=(int*)malloc(sizeof(int*)*3);
	}
	
	for(i=0 ; i<3 ; i++){
		for(j=0 ; j<3 ; j++){
			p1[i][j]=1+rand()%9;
			p2[i][j]=1+rand()%9;
		}
	}
	for(i=0 ; i<3 ; i++){
		for(j=0 ; j<3 ; j++){
			printf("%3d",p1[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	for(i=0 ; i<3 ; i++){
		for(j=0 ; j<3 ; j++){
			printf("%3d",p2[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	for(i=0 ; i<3 ; i++){
		for(j=0 ; j<3 ; j++){
			p1[i][j]+=p2[i][j];
			printf("%3d",p1[i][j]);
		}
		printf("\n");
	}
	return 0;
}

10. 3 10 . 는 반드 다. 모르면 물되고, 다른 드를
LinearSearch를 구. 배 1000개로 고, random 1부 1000까 를 랜덤로 배 , 777 면 됩다. 로그램 다 결과가 달라?
(rand()%1000 다면 1 1000까 가 나다.)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(){
	int arr[1000];
	int i;
	int count=0;
	srand(time(NULL));

	for(i=0 ; i<1000 ; i++){
		arr[i]=rand()%1000;
	}
	
	for(i=0 ; i<1000 ; i++){
		if(arr[i]==777){
			printf("%d 777 \n",i+1);
			count++;
		}
	}
	printf("%d개 \n",count);
	if(count == 0){
		printf("777\n");
	}
	
	return 0;
}

11. 던 내로, int* a; int b; int **c;로 때 &c,c,*c,&a,a 각각 고, 떤 것 떤 것과 는 것 말로 .
	int* a;
	int b=10;
	int** c;

	a=&b;
	c=&a;
	printf("%d\n",a);  //b 
	printf("%d\n",&a); //a 
	printf("%d\n",*a); //b 값
	printf("%d\n",b); //b 값
	printf("%d\n",&b); //b 
	printf("%d\n",c); //a 
	printf("%d\n",&c); //c 
	printf("%d\n",*c); //b 


12. 드가 고, 그런 값 다.
int* a;
int b=5;
int** c;
 c=&a;
 a=&b;
 **c=9;
 printf("%d %d",*c,**c);

b가 9로 변!




1. LinkedList node를 는 방법 보고, 그런 .

struct Node{
int data; //데를 담
struct Node *NextNode; //다 노드
};


2. Circular Queue가 무 .
(arrangement) 를 구는 배 과 끝 를 말다.
, 과 끝내는 두개 게 된다.
료를 때는 , 꺼낼때는 내는 당되는 게 된다.
때는 료를 때 다 는 것다. 때는 다 가르 로 돌가게 면 된다.


3. typedef가 무 보고, .
typedef 명령문 게끔 는 명령문
<typedef 법>
typedef <> <명>;

<typedef >
typedef int AA;
AA num=500;



4. 구 student 구나 만들고, student 구 만들 0~3 AClass 보를 고, 그것 .
내부 char 배 고, int 다.
가 무 되는 경 반드 게 물보고, 과다.
#include <stdio.h>

struct student{
	char name[20];
	int num;
	int age;
};

int main(){
	int i;
	struct student aclass[3]={{"곽길문",201001,24},
				  {"",201002,23},
				  {"림",201003,22}};

	for(i=0 ; i<3 ; i++){
		printf("%s %d %d\n",aclass[i].name,aclass[i].num,aclass[i].age);
	}
	return 0;
}



1~6 공:D
10.3 10 . 는 반드 다. 모르면 물되고, 다른 드를
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

int main(void){
	int i,ran,arr[1000]={0};
	
	srand(time(NULL));

	for(i=0;i<1000;i++){
		ran = 1+rand()%1000;
	}
		if(arr[i]==777){
			printf("777I arr[%d] 다",i);
		}

		else
			printf("777I 다.");
		

		
	return 0;
}



12. 드가 고, 그런 값 다.
int* a;
int b=5;
int** c;
c=&a;
a=&b;
  • *c=9;
    printf("%d %d",*c,**c);

*c는 값, **c는 9




1.LinkedList node를 는 방법 보고, 그런 .
NODE*CreateNode(char name [])
{
NODE*NewNode = (NODE*)malloc(sizeof(NODE));

Strcpy(NewNode->Name,name);
NewNode->NextNode = NULL;

Return NewNode;
}

NODE* 를 반CreateNode다. NewNode라는 malloc로 공 다.
Malloc 가 끝나 는다. 다른 메모리 공 기 때문다.(?????)



2. Circular Queue가 무 .
를 구는 가 방법 로 배 는 방법다. 그러나 단 기가 가되게 되면 overflow 가 발게 됨로 데가 배 기를 게 되면, 과된 데는 0로 들가게 다. 같다고 (circular queue) 라고


3. typedef가 무 보고, .
1)기 로그램 내부 다른 는 것
Typedef 기____;
) typedef unsigned char uchar;
2) typedef
Typedef는 공 모든
//typedef를 다.

#include<stdio.h>
typedef int Num;
int main(){
	Num a=10;
	int b=20;

	printf("sum = %d\n",a+b);

	return 0;
}

typedef 면 int나 char 는 명로 바꾸 가능다.
typedef 다. 는 int NUM로 명 바꾼 것다.

그리고 보 int 면 된다. NUM 값과, int를 보면 게 값다.

4. 구 student 구나 만들고, student 구 만들 0~3 AClass 보를 고, 그것 .
o 구 내부 char 배 고, int 다.
o 가 무 되는 경 반드 게 물보고, 과다.
#include<stdio.h>
#include<string.h>

int main(void){
	
	struct student{
		char name[10];
		int age;
	};
	struct student s[4];
	int i;

	strcpy(s[0].name,"");
	s[0].age = 23;

	strcpy(s[1].name,"");
	s[1].age = 24;

	strcpy(s[2].name,"곽길문");
	s[2].age = 24;

	strcpy(s[3].name,"림");
	s[3].age = 22;

	for(i=0;i<4;i++){
	printf(" : %s\n",s[i].name);
	printf("나 : %d\n",s[i].age);
	}

	return 0;
}



Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:45
Processing time 0.0408 sec