Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zzoxi提交作业 #67

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
6 changes: 1 addition & 5 deletions C语言学习笔记.md
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# C语言学习笔记

# 记录你学习过程中的所见所思!酸甜苦辣!

# 看什么看! 赶紧填坑啊!
# C语言学习笔记## 关于头文件一个自定义头文件里面一般包含有函数声明、声明变量、宏定义、系统函数标准库声明等 用如下条件语句编写头文件```#ifndef _A_H //一般是头文件名#define _A_H...#endif```这样一个工程文件里同时包含两个test.h时,就不会出现重定义的错误了。使用#ifndef可以避免下面这种错误:如果在h文件中定义了全局变量,一个c文件包含同一个h文件多次,如果不加#ifndef宏定义,会出现变量重复定义的错误;如果加了#ifndef,则不会出现这种错.###实际过程中出现的问题多文件编译时链接文件出现错误。如collect2.exe[Error] ld returned 1 exit status 可能是由于头文件中定义了变量,在多个文件引用后编译出现错误 在规范头文件内容编写后,错误解决在头文件中出现error: expected identifier before numeric constant 是因为宏定义采用的标识符与引用的头文件内容出现了重复,换一个标识名即可 extern的功能是声明定义在其他文件中的变量,而不是声明定义在其他函数中的变量。## 关于数组字符串数组不能采用= 来赋值 可以使用strcpy(destination,"zz"); 来赋值或采用定义字符串型数组指针的方式 `char * arr[]="abcde"`
Expand Down
6 changes: 6 additions & 0 deletions level0/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<stdio.h>
int main()
{
printf("hello,i am ZhouZhou");
return 0;
}
38 changes: 38 additions & 0 deletions level1/p01_runningLetter/runningletter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<stdio.h>
#include<windows.h>
#include<string.h>
#define width 120//����̨������֪120
int main(void)
{
int i,j,k,n;
char str2[] ="w";
char str3[] =" ";
for(i=0;;i++)
{
j=i/width;
k=i%width;
char str1[width] ="";
n=0;
if(j%2==0)//�����ƶ�ʱ
{
while(n<k)
{
strcat(str1,str3);
++n;
}
}
else//�����ƶ�ʱ
{
while(n>k-width+1)
{
strcat(str1,str3);
--n;
}
}
strcat(str1,str2);
printf("%s",str1);
Sleep(100);
system("cls");
}
return 0;
}
19 changes: 19 additions & 0 deletions level1/p02_isPrime/isprime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
#include<math.h>
int main(void)
{
int temp,x,i;
printf("input a number to determine whether it is a prime number.\n");
scanf("%d",&x);
temp=sqrt(x);
for(i=2;i<=temp;i++)
{
if(x%i==0)
{
printf("%d is not a prime number",x);
return 0;
}
}
printf("%d is a prime number",x);
return 0;
}
17 changes: 17 additions & 0 deletions level1/p03_Diophantus/Diophantus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int main(void)
{
int age;
int a1,a2,a3,a4;
int a5=(4+5);//������
a1=6,a2=12,a3=7,a4=2;
printf("the equation is x/%d + x/%d + x/%d + 5 + 4 = x/%d\n",a1,a2,a3,a4);
int tol=a1*a2*a3*a4;
a1=tol/a1;
a2=tol/a2;
a3=tol/a3;
a4=tol/a4;
a5=tol*a5;
age=a5/(a4-a1-a2-a3);
printf("the diophantus's age is %d",age);
}
File renamed without changes.
18 changes: 18 additions & 0 deletions level1/p04_narcissus/narcissus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
int main(void)
{
int a,b,c,s;
printf("narcissistic numbers 100~999\n");
for (int i=100;i<=999;i++)
{
a=i/100;
b=i/10%10;
c=i%10;
s=a*a*a+b*b*b+c*c*c;
if(s==i)
{
printf("%d\n",i);
}
}
return 0;
}
20 changes: 20 additions & 0 deletions level1/p05_allPrimes/allprimes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
#include<math.h>
#include<time.h>
int main(void)
{
int temp;
printf(" 2 3");
for(int i=5;i<=1000;i++)
{
temp=sqrt(i);
for(int j=2;j<=temp;j++)
{
if(i%j==0)break;
if(j==temp) printf("%4d",i);
}

}
printf("\n Time used = %.4f s\n",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
41 changes: 41 additions & 0 deletions level1/p06_Goldbach/Goldbach.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include<stdio.h>
#include<math.h>
int prime(int num);
int main (void)
{
int i,n;
int judge=0;
for(i=4;i<=100;i=i+2)
{
for(n=2;n<=i/2;n++)
{
if(prime(n)&&prime(i-n))
{
printf("%d=%d+%d\n",i,n,i-n);
judge++;
}
}
if(judge==0) //�ж��Ƿ�ÿ�������ֽܷ⣬�����ֽܷ������
{
printf("the law is wrong");
return 0;
}
}
printf("the law is right between 1-100");
return 0;
}

int prime(int num)//�ж��Ƿ�������
{
int temp=sqrt(num);
if (num==2||num==3) return 1;
else
{
int k;
for(k=2;k<=temp;k++)
{
if(num%k==0) return 0;
}
return 1;
}
}
3 changes: 0 additions & 3 deletions level1/p06_Goldbach/README.md

This file was deleted.

9 changes: 9 additions & 0 deletions level1/p07_encrypt_decrypt/a.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _A_H_
#define _A_H_

#include<stdio.h>
#include<string.h>

void decrypt(void);
void encrypt(void);
#endif
31 changes: 31 additions & 0 deletions level1/p07_encrypt_decrypt/encrypt_decrypt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "a.h"
void encrypt()//����
{
int i;
char str[10];
char ciphertext[10];
int n;
scanf("%s",str);
n=strlen(str);
for(i=0;i<n;i++)
{
ciphertext[i]=str[i]+5;
}
ciphertext[n]='\0';
printf("%s",ciphertext);

}
void decrypt()//����
{ int i;
char str[10];
char ciphertext[10];
int n;
scanf("%s",ciphertext);
n=strlen(ciphertext);
for(i=0;i<n;i++)
{
str[i]=ciphertext[i]-5;
}
str[n]='\0';
printf("%s",str);
}
21 changes: 21 additions & 0 deletions level1/p07_encrypt_decrypt/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "a.h"
int main(void)
{ int a;
printf("������һ������ 1�������� 0��������");
scanf("%d",&a);
if(a==1)
{
encrypt();
}
else if(a==0)
{
decrypt();
}
else
{
printf("��������");
}
return 0;
}


16 changes: 16 additions & 0 deletions level1/p08_hanoi/hanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include"hanoi.h"
void move(char from,char to);
extern long long count;
void hanoi(int n,char from,char help,char to)
{
if(n==0) return;
count++;
hanoi(n-1,from,to,help);
move(from,to);
hanoi(n-1,help,from,to);
}
void move(char from,char to)
{
printf("%c-->%c\n",from,to);
}

7 changes: 7 additions & 0 deletions level1/p08_hanoi/hanoi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _HANOI_H
#define _HANOI_H

#include<stdio.h>
void hanoi(int n,char from,char help,char by);

#endif
8 changes: 8 additions & 0 deletions level1/p08_hanoi/mainhanoi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "hanoi.h"
long long count=0;
int main(int argc, char *argv[])
{
hanoi(64,'A','B','C');
printf("�ܹ�ִ����%lld��",count);
return 0;
}
10 changes: 10 additions & 0 deletions level1/p09_maze/mainmaze.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include"maze.h"
#include<stdio.h>
#include<conio.h>
#include<windows.h>
int main(int argc, char *argv[])
{
printmap();
game();
return 0;
}
18 changes: 18 additions & 0 deletions level1/p09_maze/maze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _MAZE_H
#define _MAZE_H

void printmap();
void game();
#define M 16
#define WALL 0
#define ROAD 1
#define START 2
#define END 3
#define UP 4
#define DOWN 5
#define LEFT 6
#define RIGHT 7
#define ESC 8

#endif

Loading