![](https://img-blog.csdnimg.cn/20190918140037908.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
C语言-课本例题
无
小白不会写代码i
这个作者很懒,什么都没留下…
展开
-
C课本例题-1.1输出一行信息
/* 在屏幕上输出一行信息 this is a C program. */ #include <stdio.h> int main() { printf("this is a C program.\n"); return 0; }原创 2018-08-21 11:45:18 · 406 阅读 · 0 评论 -
C课本例题-2.4求 1-1/2+1/3-...+1/99-1/100的和
/* 求 1-1/2+1/3-...+1/99-1/100的和 */ #include <stdio.h> int main() { int s; double i; float sum; s=1; sum=1.0; for(i=2;i<=100;i++) { s=-s; sum=s...原创 2018-08-24 15:10:09 · 252 阅读 · 1 评论 -
C课本例题-2.3判断闰年
/* 判断2000-2100年中的每一年是否为闰年 */ #include <stdio.h> int main() { int year=2000; while(year<=2100) { if((year%4 ==0 && year%100 !=0) || year%400==0) pr...原创 2018-08-24 15:12:17 · 281 阅读 · 0 评论 -
C课本例题-1.3求两个整数中较大者
/* 输入a,b 求两个数中的较大者 */ #include <stdio.h> int main() { int a,b,c; scanf("%d %d",&a,&b); c=max(a,b); printf("the max number is %d.\n",c); return 0; } int max(int x,int...原创 2018-08-24 14:12:33 · 1231 阅读 · 0 评论 -
C课本例题-1.4求三个整数中较大者
/* 输入a,b,c 求三个整数中的较大者 */ #include <stdio.h> int main() { int a,b,c,d; scanf("%d %d %d",&a,&b,&c); d=max(a,b,c); printf("the max number is %d.\n",d); return 0; } ...原创 2018-08-24 14:09:17 · 2227 阅读 · 0 评论 -
C课本例题-2.1求n的阶乘
/* 求n的阶乘 */ #include <stdio.h> int main() { int n,i,r,res; scanf("%d",&n); r=1; res=1; while(n>1) { res=n*(n-1); r=r*res; n=n-2; }...原创 2018-08-24 14:03:29 · 257 阅读 · 0 评论 -
C课本例题-1.2求两个整数之和
/* 求两个整数之和 */ #include &amp;lt;stdio.h&amp;gt; int main() { int a,b,sum; a=3; b=4; sum=a+b; printf(&quot;sum=%d.\n&quot;,sum); return 0; } 输出结果: sum=7.原创 2018-08-21 11:53:11 · 286 阅读 · 0 评论 -
C课本例题-2.5判断一个数是否为素数
/* 给出一个大于或等于3的正整数,判断他是不是一个素数 */ #include <stdio.h> int main() { int a,b; scanf("%d",&a); if(a>=3) { b=prime(a); if(b==1) printf("不是素数"); else printf("是素数"); return 0; ...原创 2018-08-24 15:08:19 · 289 阅读 · 0 评论