#include
int main(){
unsigned long a,b,cnt,i,n1,n2,n;
scanf("%ld %ld",&a, &b);
n2=1;
n1=2;
cnt=0;
for(i=3;i=a && n<=b)
{
cnt++;
printf("cnt %ld : %ld\n", cnt, n );
}
n2 = n1;
n1 = n;
}
printf("%ld\n", cnt);
}
2018/07/08
[c] Fibonacci
[c] Mine Sweep
#include
#include
#include
#include
#define debug_
char mine[100][100];
int nmax = 0, mmax = 0;
int getMin(int a, int b){
if(a>b)
return b;
else
return a;
}
int getMax(int a, int b){
if(a>b)
return a;
else
return b;
}
int getCnt(int x, int y){
int i = 0, j = 0, cnt = 0;
for(i=getMax(x-1, 0);i<=getMin(x+1, nmax);i++){
for(j=getMax(y-1, 0);j<=getMin(y+1, mmax);j++){
if(mine[i][j] == '*'){
cnt ++;
}
#ifdef debug
printf("---- getCnt : i:%d, j:%d, cnt:%d\n", i, j, cnt);
#endif
}
}
return cnt;
}
int main(){
char buf[101];
int s, i, j, n, m;
s = 1; /* Set counter */
n = 0; /* Row counter in set */
m = 0; /* Column counter in row */
while(gets(buf)){
if(strlen(buf) < 1)
break;
if(n == 0){
nmax = buf[0] - '0';
mmax = buf[2] - '0';
#ifdef debug
printf("---- nmax : %d, mmax : %d\n", nmax, mmax);
#endif
if(nmax == 0 && mmax == 0)
break;
}
else{
for(j=0;j < mmax;j++){
mine[n-1][j] = buf[j];
#ifdef debug
printf("---- n : %d, m : %d, char : %c\n", n, j, mine[n-1][j]);
#endif
}
}
if(n == nmax){
printf("Field #%d\n", s);
for(i=0;i < nmax;i++){
for(j=0;j< mmax;j++){
if(mine[i][j] == '*')
printf("%c",'*');
else
printf("%d",getCnt(i, j));
if(j == (mmax - 1))
printf("\n");
}
}
s++;
n = 0;
memset(mine,'\0',sizeof(mine));
}
else{
n++;
}
}
return 0;
}
[c] Stack
#include
#include
#define MAXSIZE 100
typedef struct stack{
int stk[MAXSIZE];
int top;
} STACK;
void Push(int x, STACK *s){
int num;
s->top ++;
printf("Push %d\n", s->top);
s->stk[s->top] = x;
return;
}
int Pop(STACK *s){
int num;
printf("Pop %d\n", s->top);
num = s->stk[s->top];
s->top --;
return num;
}
void Init(STACK *s){
s->top = -1;
printf("Init %d\n", s->top);
return;
}
int main(){
STACK *s = (STACK *)malloc(sizeof(STACK));
Init(s);
Push(1, s);
Push(2, s);
Push(3, s);
printf("%d\n", Pop(s));
printf("%d\n", Pop(s));
printf("%d\n", Pop(s));
}
2018/07/07
[c] learn-c.org
Welcome
Welcome to the learn-c.org free interactive C tutorial.Whether you are an experienced programmer or not, this website is intended for everyone who wishes to learn the C programming language.
There is no need to download anything - Just click on the chapter you wish to begin from, and follow the instructions. Good luck!
http://www.learn-c.org
2016/08/27
피보나치(Fibonacci) in C
#include
/* buff array for memorization */
int buf[10001];
/* buff array initialize */
void init(int arr[], int s){
int i;
buf[0]=0;
buf[1]=1;
buf[2]=2;
for(i=3;i
arr[i]=0;
}
}
/* Fibonacci main function */
int Fibo(int i){
if(but[i] != 0) return i;
return Fibo(i-1) + Fibo(i-2);
}
C 에서의 time 측정
#include
clock_t begin, end;
double time_spent;
begin = clock();
/* here, do your time-consuming job */
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
피드 구독하기:
덧글 (Atom)