#include
int main()
{
#if 1
int year;
#if 0
scanf("%d", &year);
#endif
if((year%4==0 && year%100!=0) || year%400==0)
printf("yes\n");
else
printf("no\n");
#endif
return 0;
}
#include
int main()
{
int i;
for(i = 0; i < 10; i++)
{
if(i%2)
break;
printf("%d ", i);
}
printf("break\n");
for(i = 0; i < 10; i++)
{
if(i%2)
continue;
printf("%d ", i);
}
printf("continue\n");
return 0;
}
#include
int main()
{
srand(time(NULL));
printf("%d %d\n", rand()%7 + 1, rand()%5 + 1);
return 0;
}
#include
int main()
{
int year, month, days;
printf("please input a year and a month(YYYY-MM):")
scanf("%d-%d", &year, &month);
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
days = 28;
break;
}
if((month == 2) && (year%4==0&&year%100!=0||year%400==0))
days += 1;
printf("days = %d\n", days);
return 0;
}
#include
int main()
{
int i;
int ge, shi, bai;
for(i = 100; i < 1000; i++)
{
bai = i / 100;
shi = i % 100 / 10;
ge = i % 10;
if(bai*bai*bai + shi*shi*shi + ge*ge*ge == i)
printf("%d ", i);
}
printf("\n");
return 0;
}
#include
int main()
{
int i;
int nu;
scanf("%d", &nu);
for(i = 0; i < nu; i++)
{
faboccia(i);
}
printf("\n");
return 0;
}
#include
int main()
{
int i, j;
int flag;
for(i = 2; i < 100; i++)
{
flag = 1;
for(j = 2; j <= i/2; j++)
{
if(i%j == 0)
{
flag = 0;
break;
}
}
if(flag == 1)
printf("%d ", i);
}
printf("\n");
return 0;
}
#include
int main()
{
int nu = 3;
switch(nu)
{
case 1:
printf("1\n");
break;
case 2:
printf("2\n");
break;
case 3:
printf("3\n");
break;
default :
printf("error\n");
break;
}
return 0;
}
#include
int faboccia(int nu)
{
static int a = 1;
static int b = 1;
int c;
if(nu == 0 || nu == 1)
return 1;
c = a + b;
a = b;
b = c;
return c;
}
int faboccia1(int nu)
{
if(nu == 0 || nu == 1)
return 1;
return faboccia1(nu-2) + faboccia1(nu-1);
}
int main()
{
int i;
int nu;
scanf("%d", &nu);
for(i = 0; i < nu; i++)
{
printf("%d ", faboccia1(i));
}
printf("\n");
return 0;
}
#include
void itoa(int nu)
{
if(nu < 0)
{
putchar('-');
nu = -nu;
}
if(nu/10)
itoa(nu/10);
putchar(nu%10 + '0');
putchar(' ');
}
int main()
{
printf("-273345\n");
itoa(-273345);
return 0;
}
#include
int main()
{
int arr[100] = {0};
int i, j;
for(i = 2; i < 100; i++)
{
if(arr[i] == 0)
for(j = i+i; j < 100; j+=i)
arr[j] = 1;
}
for(i = 2; i < 100; i++)
if(arr[i] == 0)
printf(" %d ", i);
printf("\n");
return 0;
}
#include
int print(int *arr)
{
int i = 0;
while(arr[i])
printf("%d ", arr[i++]);
printf("\n");
return i;
}
int main()
{
int arr[100] = {3,1,5,2,7,9};
int res = print(arr);
printf(" %d \n", res);
return 0;
}
#include
int main()
{
int nu;
int i;
int arr[47] = {1, 1};
scanf("%d", &nu);
if(nu > 2 && nu < 47)
{
for(i = 2; i < nu; i++)
{
arr[i] = arr[i - 2] + arr[i - 1];
}
}
else if(nu >= 47)
{
printf("error\n");
return -1;
}
for(i = 0; i < nu; i++)
printf("%d ", arr[i]);
return 0;
}
#include
#define SIZE 100
int change(int arr[], int num, int base)
{
int i = 0;
while(num)
{
arr[i] = num % base;
num /= base;
i++;
}
return i;
}
void print(int *arr, int nu)
{
printf("sizeof = %d\n", sizeof(arr));
for(; nu >= 0; nu--)
{
if(arr[nu] > 9)
putchar(arr[nu] - 10 + 'A');
else
printf("%d", arr[nu]);
}
}
int main()
{
int arr[SIZE] = {0};
int num, base;
int i;
int res;
printf("please input a number:");
scanf("%d", &num);
printf("please input another number(2,8,16):");
scanf("%d", &base);
res = change(arr, num, base);
printf(" ");
print(arr, res - 1);
putchar('\n');
return 0;
}
#include
int main()
{
char str[100];
int count = 0;
int flag = 1;
int i;
gets(str);
for(i = 0; str[i] != '\0'; i++)
{
if(str[i] == ' ')
flag = 1;
else
if(flag == 1)
{
flag = 0;
count++;
}
}
printf("there is %d words\n", count);
return 0;
}
#include
//#include
#include //malloc.h
char *strcpy_(char * dest, char *src)
{
char * ptr = dest;
while(*dest++ = *src++);
// while((*dest = *src) != '\0')
// {dest++;
// src++;}
return ptr;
}
int main()
{
char *p = "hello";
char arr[10];
char * str;// = (char *)malloc(10);
str = strcpy_(arr, p);
puts(arr);
puts(str);
return 0;
}
#include
#define SIZE 100
int print(int *arr)
{
int i = 0;
while(arr[i])
printf("%d ", arr[i++]);
printf("\n");
return i;
}
int find_value(int *arr, int value)
{
int i = 0;
while(arr[i])
{
if(arr[i] == value)
return i;
i++;
}
return -1;
}
int length(int *arr)
{
int i = 0;
while(arr[i++]);
return i - 1;
}
int find_location(int *arr, int location)
{
if(location >= 0 && location < length(arr))
return arr[location];
return 0;
}
void swap(int *arr, int x, int y)
{
int nu = arr[x];
arr[x] = arr[y];
arr[y] = nu;
}
void sort_down(int *arr)
{
int i, j;
int res = length(arr);
for(i = 0; i < res; i++)
{
for(j = 0; j < res - 1; j++)
if(arr[j] < arr[j+1])
swap(arr, j, j+1);
}
}
void sort_up(int *arr)
{
int i, j, base;
for(i = 0; arr[i]; i++)
{
base = i;
for(j = i+1; arr[j]; j++)
if(arr[base] > arr[j])
base = j;
swap(arr, i, base);
}
}
int find_(int *arr, int value)
{
int i = 0;
while(arr[i])
{
if(arr[i] >= value)
return i;
i++;
}
return -1;
}
int insert(int *arr, int value)
{
int len = length(arr);
int res = find_(arr, value);
if(res == -1)
{
arr[len] = value;
return 0;
}
for(; len != res; len--)
{
arr[len] = arr[len - 1];
}
arr[res] = value;
return 0;
}
int delete(int *arr, int value)
{
int res = find_value(arr, value);
if(res == -1)
return -1;
int len = length(arr);
arr[res] = 0;
for(; res != len-1; res++)
swap(arr, res, res+1);
return 0;
}
int main()
{
int arr[SIZE] = {3,1,5,2,7,9};
int res = print(arr);
//res = length(arr);
//res = find_location(arr, 14);
//printf(" %d \n", res);
/*******sort_down*************/
#if 0
sort_down(arr);
print(arr);
#endif
/*******sort_up*************/
sort_up(arr);
print(arr);
insert(arr, 4);
print(arr);
res = delete(arr, 4);
if(res == -1)
printf("delete fail\n");
print(arr);
return 0;
}
#include
void paint(int arr[][15])
{
int i, j;
printf("\33[1;1H ");
for(i = 0; i < 15; i++)
{
printf(" %x", i);
}
putchar('\n');
for(i = 0; i < 15; i++)
{
printf("%x ", i);
for(j = 0; j < 15; j++)
{
switch(arr[i][j])
{
case 0:
printf(" ");
break;
case 1:
printf("* ");
break;
case 2:
printf("0 ");
break;
}
}
printf("\n");
}
}
int play(int arr[][15], int x, int y, int value)
{
if(x>=0 && x<15 && y>=0 && y<15)
if(arr[x][y] == 0)
{
arr[x][y] = value;
return 1;
}
return 0;
}
int win(int arr[][15], int x, int y, int value)
{
return f1()||f2()||f3()||f4();
}
int main()
{
int nu = 0;
int x, y;
int arr[15][15] = {0};
paint(arr);
while(1)
{
printf("%c >:", 'A' + nu%2);
scanf("%x %x", &x, &y);
if(play(arr, x, y, nu%2+1))
{
system("clear");
paint(arr);
if(win(arr, x, y, nu%2+1))
break;
nu++;
}
}
printf("%c is a winer!\n", 'A' + nu%2);
return 0;
}
#include
int main()
{
printf("\33[2J\33[%d;%dH\33[41mHello world!\33[0m\n", 1, 1);
return 0;
}
#include
int main()
{
int arr[3][2] = {1,2,3,4,5,6};
int (*p)[2];
p = arr;
p[1][1] = 9;
int i, j;
for(i = 0; i < 3; i++)
for(j = 0; j < 2; j++)
printf(" %d\n", arr[i][j]);
return 0;
}
#include
#include
int fun(int , int );
int cal(int , int , int (*fp)());
int fun(int a, int b)
{
return a+b;
}
int cal(int a, int b, int (*fp)())
{
return fp(a, b);
}
int mycmp(char *dest, char *src, int (*fp)())
{
return fp(dest, src);
}
int main()
{
char *str = "hello";
char arr[10] = "helll";
int res = mycmp(str, arr, strcmp);
printf(" %d \n", res);
#if 0
char *(*funp)();
int (*fp)(int, int);
fp = fun;
funp = &strcpy;
//funp = strcpy;
//funp(arr, str);
(*funp)(arr, str);
puts(arr);
printf(" %d \n", fp(3, 4));
#endif
return 0;
}
#include
int *fun1()
{
int nu = 34;
int *p = ν
return p;
}
int *fun2()
{
int nu = 56;
int *p = ν
return p;
}
int main()
{
int *data_p = NULL;
int *(*p)();
int *(*q)();
p = fun1;
q = fun2;
data_p = p();
q();
printf(" %d \n", *data_p);
return 0;
}
#include
#include
#include
void mymalloc(void ** q, int size)
{
*q = malloc(size);
}
int main()
{
char arr[] = "hello";
char *p = NULL;
mymalloc((void **)&p, 10);
strcpy(p, arr);
puts(p);
return 0;
}
#include
int fun(int *p)
{
*p = 7;
}
int main()
{
int nu = 5;
int *p = ν
printf("&nu = %p\np = %p\n", &nu, p);
printf("*p = %d\n", *p);
printf(" %d\n", nu);
//nu = 8;
*p = 6;
printf("&nu = %p\np = %p\n", &nu, p);
printf("*p = %d\n", *p);
printf(" %d\n", nu);
fun(&nu);
printf(" %d\n", nu);
return 0;
}
#include
#include
int main()
{
int i = 6;
while(i--)
{
printf("*");
sleep(1);
fflush(stdout);
}
printf("\n");
return 0;
}
#include
int main()
{
char arr[10] = "hello";
char *p;
printf(" &p = %p\n", &p);
p = arr;
printf(" p = %p\n", p);
printf(" arr = %p\n", arr);
printf(" &arr[9] = %p\n", &arr[9]);
printf(" *p = %c\n", *p);
printf(" arr[0] = %c\n", arr[0]);
return 0;
}
#include
enum en{red, black, blue, gray, yellow};
//#define red 0
int main()
{
int i;
enum en nu = red;
nu = blue;
printf("size is %d\n", sizeof(nu));
for(i = red; i <= yellow; i++)
printf(" %d \n", i);
return 0;
}
#include
#include
#include
typedef struct student{
int ID;
char name[20];
char ***;
int score;
}STU, *STUP, **STUPP;
void print(STUP stup)
{
printf("================\n");
printf("ID:%d\nname:%s\n***:%c\nscore:%d\n",
stup->ID,
stup->name,
(*stup).***,
(*stup).score);
}
int main()
{
struct student stu = {123, "abc", 'f', 98};
printf("size is %d\n", sizeof(stu));
struct student stu1;
stu1.ID = 124;
stu1.*** = 'm';
stu1.score = 76;
strcpy(stu1.name, "hello");
struct student stu2;
stu2 = stu;
stu2.ID = 125;
STU stu3 = stu1;
STUP stup;
stup = (STUP)malloc(sizeof(*stup));
print(&stu);
print(&stu1);
print(&stu2);
print(&stu3);
return 0;
}
#include
#include
typedef struct time{
int year;
int month;
int day;
}DATE;
typedef struct goods{
char good_name[20];
int price;
int count;
}GOOD;
typedef struct menu{
char super_name[20];
char name[20];
DATE date;
GOOD good;
char money_type[5];
}MENU;
void print(MENU* p)
{
printf("super_name:%s\nname:%s\ndate:%d-%d-%d\n \
good:%s\nprice:%d\ncount:%d\nmoney:%d \
money type:%s\n",
p->super_name,
p->name,
p->date.year,
p->date.month,
p->date.day,
p->good.good_name,
p->good.price,
p->good.count,
p->good.price*p->good.count,
p->money_type);
}
int main()
{
MENU me;
strcpy(me.super_name, "chaoshifa");
strcpy(me.name, "abc");
printf("please input the date:(YYYY-MM-DD):");
scanf("%d-%d-%d", &me.date.year,
&me.date.month,
&me.date.day);
printf("input good name:");
scanf("%s", me.good.good_name);
printf("input good price:");
scanf("%d", &me.good.price);
printf("input good count:");
scanf("%d", &me.good.count);
printf("input money type:");
scanf("%s", me.money_type);
print(&me);
return 0;
}
#include
union un{
int i;
float f;
double d;
char c;
};
int main()
{
union un nu1;
printf("size is %d\n", sizeof(nu1));
nu1.i = 256;
printf(" %d \n", nu1.i);
printf(" %c \n", nu1.c);
return 0;
}
#include
int main(int argc, char **argv)
{
if(argc < 3)
{
printf("Usage...\n");
return 1;
}
FILE *fr = fopen(argv[1], "r");
FILE *fw = fopen(argv[2], "w");
if(fr == NULL || fw == NULL)
{
printf("fopen() error\n");
return -1;
}
char c = 0;
while((c = fgetc(fr)) != EOF)
fputc(c, fw);
fclose(fr);
fclose(fw);
return 0;
}
#include
int main()
{
FILE *fp = fopen("tmp", "w");
if(fp == NULL)
{
printf("fopen() error\n");
return -1;
}
int arr[5] = {0};
int nu = 65;
fwrite(&nu, sizeof(int), 1, fp);
#if 0
fputc('r', fp);
int res = fputs("hello", fp);
printf("%d\n", res);
#endif
#if 0
char c = fgetc(fp);
printf(" %c\n", c);
char arr[10];
fgets(arr, 4, fp);
printf("%s\n", arr);
#endif
fclose(fp);
fp = fopen("tmp", "r");
if(fp == NULL)
{
printf("fopen() error\n");
return -1;
}
int res = 2;
fread(&res, sizeof(int), 1, fp);
printf("res = %d\n", res);
fclose(fp);
return 0;
}
#include
#include
#define SIZE 20
typedef struct student{
int ID;
char name[SIZE];
char ***;
int score;
}DATA;
typedef struct node{
DATA data;
struct node *next;
}LIST, *LISTP;
int create(LISTP * head, DATA *tmp)
{
LISTP cur = (LISTP)malloc(sizeof(*cur));
if(cur == NULL)
{
printf("malloc() fail\n");
return -1;
}
cur->data = *tmp;
cur->next = NULL;
#if 0
if(*head == NULL)
{
*head = cur;
return 0;
}
#endif
cur->next = *head;
*head = cur;
return 0;
}
static void print(DATA *stu)
{
printf("=================\n");
printf("ID:%d\nname:%s\n***:%c\nscore:%d\n",
stu->ID,
stu->name,
stu->***,
stu->score);
}
int travel(LISTP head)
{
int i = 0;
LISTP p = head;
while(p != NULL)
{
print(&p->data);
p = p->next;
i++;
}
return i;
}
int insert(LISTP *head, DATA *tmp)
{
//创建结点
LISTP cur = (LISTP)malloc(sizeof(*cur));
if(cur == NULL)
{
printf("malloc() fail\n");
return -1;
}
cur->data = *tmp;
cur->next = NULL;
//判断链表是否为空
if(*head == NULL)
{
*head = cur;
return 0;
}
LISTP p,q;
p = *head;
//在头部插入
if(p->data.ID < tmp->ID)
{
cur->next = *head;
*head = cur;
return 0;
}
//在中间插入
for(; p != NULL; q = p, p = p->next)
{
if(p->data.ID < tmp->ID)
{
q->next = cur;
cur->next = p;
return 0;
}
}//尾部插入
q->next = cur;
return 0;
}
LISTP find(LISTP head, int id)
{
LISTP p = head;
for(; p != NULL; p = p->next)
if(p->data.ID == id)
return p;
return NULL;
}
int delete(LISTP * head, int id)
{
LISTP p, q;
if((*head)->data.ID == id)
{
p = *head;
*head = (*head)->next;
free(p);
p = NULL;
return 0;
}
for(p = *head; p != NULL; q = p, p = p->next)
{
if(p->data.ID == id)
{
q->next = p->next;
p->next = NULL;
free(p);
p = NULL;
return 0;
}
}
return -1;
}
int destroy(LISTP *head)
{
int i = 0;
LISTP p;
while(*head != NULL)
{
p = *head;
*head = p->next;
free(p);
i++;
}
return i;
}
int main()
{
LISTP head = NULL;
DATA tmp;
int i;
for(i = 0; i < 6; i++)
{
tmp.ID = i;
snprintf(tmp.name, SIZE, "stu%d", i);
tmp.*** = 'f';
tmp.score = 100 - i;
create(&head, &tmp);
}
/************insert***************/
#if 0
i = 8;
tmp.ID = i;
snprintf(tmp.name, SIZE, "stu%d", i);
tmp.*** = 'f';
tmp.score = 100 - i;
insert(&head, &tmp);
i = 7;
tmp.ID = i;
snprintf(tmp.name, SIZE, "stu%d", i);
tmp.*** = 'f';
tmp.score = 100 - i;
insert(&head, &tmp);
#endif
/**********find****************/
LISTP cur= find(head, 10);
if(cur == NULL)
printf("there is no the student\n");
else
print(&cur->data);
/**********delete****************/
//delete(&head, 5);
travel(head);
int res = destroy(&head);
printf("res = %d", res);
return 0;
}
#include
int main(int argc, char **argv)
{
printf("argc = %d\n", argc);
printf("argv[0] %s\n", argv[0]);
printf("argv[1] %s\n", argv[1]);
printf("argv[2] %s\n", argv[2]);
return 0;
}