chapter1&&2
来源:互联网 发布:免费电子阅览室软件 编辑:程序博客网 时间:2024/06/07 04:23
输入r,h,求圆柱体的表面积,保留3位小数
#include <stdio.h>#include <math.h>int main(){const double pi = 4.0 * atan(1.0);double r, h, s1, s2, s;scanf("%lf%lf", &r, &h);s1 = pi*r*r;s2 = 2*pi*r*h;s = s1*2.0 + s2;printf("Area = %.3lf\n", s);return 0;}
%md %0md
#include <stdio.h>int main(){ int n, m; scanf("%d", &n); m = (n%10)*100 + (n/10%10)*10 + n/100; printf("%03d\n", m); return 0;}
输出所有形如aabb的四位完全平方数
代码1:
#include <stdio.h>#include <math.h>int main(){int a, b, n;double m;for(a = 1; a <= 9; a++)for(b = 0; b <=9; b++){n = a*1100 + b*11;m = sqrt(n);if(floor(m+0.5) == m)printf("%d\n", n);}return 0;}
代码2:
#include <stdio.h>int main(){int x, n, hi, lo;for(x = 1; ; x++){n = x*x;if(n < 1000)continue;if(n > 9999)break;hi = n / 100;lo = n %100;if(hi/10 == hi%10 && lo/10 == lo %10)printf("%d\n", n);}return 0;}
计时函数的应用:
#include <stdio.h>#include <time.h>int main(){const int MOD = 1000000;int i, j, n, S = 0;scanf("%d", &n);for(i = 1; i <= n; i++){int factorial = 1;for(j = 1; j <= i; j++)factorial = (factorial *j % MOD);S = (S + factorial) % MOD;}printf("%d\n", S);printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);return 0;}
define用法:
#include <stdio.h>#define INF 100000000int main(){int x, max = -INF, min = INF, count = 0, s = 0;while(scanf("%d", &x) == 1){count++;s += x;if(x < min)min = x;if(x > max)max = x;}printf("%d %d %.3lf\n", min, max, (double)s/count);return 0;}
重定向的使用:
#define LOCAL#include <stdio.h>#define INF 100000000int main(){#ifdef LOCALfreopen("g:\\in.txt", "r", stdin);freopen("g:\\out.txt", "w", stdout);#endifint x, n = 0, min = INF, max = -INF, s = 0;while(scanf("%d", &x) == 1){s += x;if(x < min)min = x;if(x > max)max = x;n++;}printf("%d %d %.3lf\n", min, max, (double)s/n);return 0;}
64位整数:在gcc、VS2008中是%lld, 在win中是%I64d
保留指定位数的小数:
一。%nf 即输出的数字占n位 当原数字位数大于n时原样输出,原数字位数小于n时输出数字左端补上空格,比如原数字为a=1.23456;n为4时输出为1.23456,n为9时输出为
(空格空格1.23456)
二。%n.mf 即输出总共占n位其中有m位小数 如a=1.23456 用%4.2f输出为1.23如果用
%5,1f输出为123.4即长度为5小数为1!这里也有当原数字长度小于n时左端补空格这个规则!
还有就是当n前面有个负号时即%-nf或%-n.mf时就右端补空格!
#include <stdio.h>int main(){int a, b, c;scanf("%d%d%d", &a, &b, &c);printf("%.*lf\n", c, (double)a/b);return 0;}
0 0
- chapter1&&2
- 《算法导论》chapter1/2
- Chapter1
- chapter1
- chapter1
- Chapter1
- chapter1
- chapter1
- chapter1
- chapter1 Oracle基础---2总结
- UsacoTraining Chapter1.2 Broken Necklace
- ejb3 in action Chapter1、2 读书笔记
- chapter1 数据库的设计---2预习检查
- UsacoTraining Chapter1.2 Greedy Gift Givers
- UsacoTraining Chapter1.2 Friday the Thirteenth
- 读书摘要--《C++.GUI.Programming.with.Qt.4》chapter1~2
- dwarf2调试信息格式——chapter1,2
- 《JavaScript 高程》笔记——chapter1/2 简介
- 植肥俅潜凳壳房谛瞎说澈刮治居敬
- python相关爬爬信息
- 顿乓谄从宦胁覆老皇研侥勘甘九雷
- View 及 ViewGroup 属性大全
- 黑马程序员第一天 Java概述与环境搭建
- chapter1&&2
- iOS 代码管理SVN
- xxx is not in the sudoers file.This incident will be reported.的解决方法
- 断点的调试
- 在sudo下php无法执行系统命令
- 安卓4.2.2 修改默认语言为中文
- 解决sudo: no valid sudoers sources found, quitting
- Android getevent/senevent
- struts 中filter使用控制session