2018年6月24日

摘要: //字符串数组 #include int main(){ char s1[]={"I am a boy"}; char s2[]={"I am a boy\0 and a student"};//遇到\0字符串结束 printf("%s\n",s1); printf("%s\n",s2); return 0; } 阅读全文
posted @ 2018-06-24 10:46 孙悟空son_ku_kong 阅读(114) 评论(0) 推荐(0)
摘要: 1 //判断一个数字是否是素数(素数只能被1和它自己整除) 2 #include 3 #include 4 int main(){ 5 int num; 6 int flag=0; 7 printf("输入一个数字:\n"); 8 scanf("%d",&num); 9 for(int i=2;i<=sqrt(num);i++){ 1... 阅读全文
posted @ 2018-06-24 10:45 孙悟空son_ku_kong 阅读(107) 评论(0) 推荐(0)
摘要: //利用格里高利公式π/4=1-1/3+1/5-1/7+...,求圆周率,要求最后一行绝对值小于10e-6 #include #include int main(){ double sum=1,k=1,m=1,t=0; do{ m=-m; k+=2; t=m/k; sum=sum+t; }while(fabs(t)>=0.000001); printf("%lf\n"... 阅读全文
posted @ 2018-06-24 10:33 孙悟空son_ku_kong 阅读(111) 评论(0) 推荐(0)
摘要: 1 //输出Fibonacci数列1,1,2,3,5,8,13,21,...的前40项 2 //经过观察,我们可以得出结论后一项是前两项之和 3 #include <stdio.h> 4 int main(){ 5 int a,b,c; 6 a=1; 7 b=1; 8 c=a+b; 9 int su 阅读全文
posted @ 2018-06-24 10:31 孙悟空son_ku_kong 阅读(116) 评论(0) 推荐(0)
摘要: //求s=10!,即求10的阶乘 start #include int main(){ int s=1; for(int i=1;i<=10;i++){ s=s*i; } printf("%d",s); return 0; } 阅读全文
posted @ 2018-06-24 10:30 孙悟空son_ku_kong 阅读(104) 评论(0) 推荐(0)
摘要: #include int main(){ char c1,c2,c3; c1=getchar(); c2=getchar(); c3=getchar(); putchar(c1); putchar(c2); putchar(c3); return 0; } 阅读全文
posted @ 2018-06-24 10:28 孙悟空son_ku_kong 阅读(124) 评论(0) 推荐(0)

导航