U E D R , A S I H C RSS

새싹교실/2012/AClass/5회차 (rev. 1.3)

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

Describe 새싹교실/2012/AClass/5회차 here
=곽길문=
1.koistudy
112-113
#include<stdio.h>

int main()
{
int r,e,c;

scanf("%d %d %d",&r,&e,&c);

if(r< e-c){
printf("advertise\n");
}else if(r>e-c){
printf("do not advertise\n");
}else if(r==e-c){
printf("does not matter\n");
}
}


#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
double x1,x2;
scanf("%d %d %d", &a,&b,&c);
x1=(-b+sqrt(b*b-(4*a*c)))/(2*a);
x2=(-b-sqrt(b*b-(4*a*c)))/(2*a);

if(x1==x2){
printf("%g ",x1);
}else if(x1 !=x2){
if(x1>x2)
printf("%g %g",x1,x2);
else if(x1

printf("%g %g",x2,x1);
}

return 0;
}
2.Swap함수 작성

--#include<stdio.h>

void swap(int *a,int *b);
int main()
{
char x='A',y='B';
printf("x= %c y=%c\n",x,y);

swap(&x,&y);
printf("x=%c ,y=%c\n",x,y);
return 0;


}
void swap(int *a,int *b)
{

int temp;
temp=*a;
*a=*b;
*b=temp;

}

  1. 3,4,6,7,9,3,2를 입력으로 넣은 후 2,3,9,7,6,4,3순서로 출력하는 프로그램을 작성해보세요.(스택)
#include<stdio.h>
#define MaxSize 7
int stackMaxSize;

int sp=0;
int push(int);
int pop(int *);

int main(){

int n=0;
push(3);
push(4);
push(6);
push(7);
push(9);
push(3);
push(2);
if (push(40) == -1)
{

printf("Stack Overflow\n");

}
pop(&n);
printf("pop : %d\n",n);

pop(&n);
printf("pop : %d\n",n);

pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);
pop(&n);
printf("pop : %d\n",n);

if(pop(&n) == -1)
{
printf("Stack Underflow\n");

}
return 0;
}


int push(int n)
{
if(sp<MaxSize)
{
stacksp=n;
sp++;
return 0;

}else
{
return -1; // 가튀�득姨�찾£을≫때納�overflow
}

}

int pop(int *n)
{
if(sp>0) //값튕�이I 있O을≫ 때納�
{
sp--;
*n=stacksp;
return 0;

}else
{
return -1; //비촱었�을≫ 때納� underflow

}
}


4.BinarySearch가 무엇인지 찾아보고, 가능하면 한번 구현해보도록 합시다.(가능하면!)

-이진 탐색은 제어검색에서 가장 대표적인 방법으로 한번 비교동작이 끝난 후 그 결과를 이용하여 다음에 비교할 대상을 선택하는 방법으로 검색한다. 주어진 파일들을 일정한 순서대로 배열된 상태에서 원하는 값을 검색하는 방법이다.

•아래와 같은 출력이 나오는 프로그램을 어떻게하면 짤 수 있는지 생각해서 써보도록 합시다. 그 방법이 확실하다고 생각되면 짜보아도 좋아요

1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9

- 5X5배열을 우선 배정, 1,2,3,4,5를 우선 0행에 출력, 마지막 4행에 도달했을 때 4열 출력, 마지막 4행에 도달했을 때 4행 출력, 0행에 도달했을 때 (전체 행수-1)만큼 출력 ... 반복....
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:45
Processing time 0.0307 sec