c++刷题一
来源:互联网 发布:metamorphosis java 编辑:程序博客网 时间:2024/05/17 08:55
(一)输出其中的最大值。#include <iostream>using namespace std;int main(){ int a,b,c,max; cin>>a>>b>>c; max=a; if(b>max) max=b; if(c>max) max=c; cout<<max<<endl;}
(二)输出y的值。
(1)#include <iostream> using namespace std; int main() { double x,y; cin>>x; if(x<1) y=x; else if(1<=x&&x<10) y=2*x-1; else if(x>=10) y=3*x-11; cout<<y<<endl; return 0; } (2)函数版#include <iostream> using namespace std; double max(double x); int main() { double x; cin>>x; cout<<max(x)<<endl; return 0; } double max(double x) { double y; if(x<1) y=x; else if(1<=x&&x<10) y=2*x-1; else if(x>=10) y=3*x-11; return y; }
(三)给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123
<span style="font-family: Arial, Helvetica, sans-serif;"><p>一个不大于5位的数字</p><p>三行第一行 位数第二行 用空格分开的每个数字,注意最后一个数字后没有空格第三行 按逆序输出这个数</p></span>
#include <iostream>using namespace std;int main(){ int n,i=0,a[10]; cin>>n; while(n>0) { i++; a[i]=n%10; n/=10; } cout<<i<<endl; for(int j=i;j>1;j--) cout<<a[j]<<" "; cout<<a[1]<<endl; for(int j=1;j<i+1;j++) cout<<a[j]; return 0;}(四)求Sn=1!+2!...+n!#include <iostream>using namespace std;int main(){ int i,n;
long long m=1,s=0;
cin>>n; for(i=1;i<=n;i++) { m=i*m; s=s+m; } cout<<s<<endl; return 0;}(五)求以下三数的和,保留2位小数 1~a之和 1~b的平方和 1~c的倒数和#include <iostream>#include <iomanip>using namespace std;int main(){ int a,b,c,s=0,m=0; double n=0,sum; cin>>a>>b>>c; for(int i=1;i<=a;i++) { m=m+i; } for(int i=1;i<=b;i++) { s=s+i*i; } for(double i=1.0;i<=c;i++) { n=1/i+n; } sum=s+m+n; cout<<setiosflags(ios::fixed)<<setprecision(2)<<sum<<endl; return 0;}
0 0
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- c
- C
- C
- c
- C
- 分享45个android实例源码,很好很强大.收藏吧!!!
- leetcode012:Integer to Roman
- 在ubuntu上安装weka
- 关于adb server is out of date的问题
- Android Activity为什么要细化出onCreate、onStart、onResume、onPause、onStop、onDesdroy这么多方法让应用去重载?
- c++刷题一
- 《启示录-打造用户喜爱的产品》-第一部分
- JavaSE 拾遗(2)——JavaSE 面向对象程序设计语言基础(2)...变量
- python基础语法2(数据结构)
- 华为机试数字倒序
- 第六周程序阅读(2)
- wget 使用
- p52 22
- 人人都是产品经理