《c++编程基础题训练答案》由会员分享,可在线阅读,更多相关《c++编程基础题训练答案(30页珍藏版)》请在金锄头文库上搜索。
1、1、输入 3 个数,求最大数。#include using namespace std;int main()int a,b,c,max;coutabc;max=(ab)?a:b;if(cmax)max=c;coutusing namespace std;int main()int a;for(a=1;ausing namespace std;int main()int s=0;int a=1;do s=s+a;a=a+;while(ausing namespace std;int main()int a,s=0,s1=0,s2=0;for(a=1;a-101;a=a-2)s2=s2+a;s=s
2、1+s2;coutusing namespace std;void main()float a,m;float s=0;for(a=1;ausing namespace std;int fac(int n)if(n=0)return 1;elsereturn fac(n-1)*n;int main()while(1) int x,y,n;coutx;fac(x);coutusing namespace std;int main()int s=0;int t=1;int n;for(n=1;nusing namespace std;void main()double s=0;double t=1
3、;double n=1;dot=t*n;s=s+1/t;n+;while (tusing namespace std;void main()double sum=0.0; /结果double now=1.0; /现在的 1n!double cnt=2.0; /现在的 nwhile(now=1e-5)sum+=now;now/=cnt;cnt+=1.0;coutusing namespace std;int pow(int x, int n);int f1(int n);int main(int argc, char* argv)int x, n;double ex = 1;cin x;cin
4、n;for (int i=1; i #includeusing namespace std; int f(int n)int sum;if (nn;f(n);for(i=1;i# includeusing namespace std;int main()int i,n,k;coutn;k=sqrt(n);for(i=2;ik)cout #includeusing namespace std; int main() int i,n,m;coutn;m=sqrt(n);for(i=2;im)cout #include int main() int n=0, i, j,w,k; for(i=2;i#
5、include using namespace std;int main()int i,j,n=0;for(i=2;iusing namespace std;int fun1(int a,int b);int fun2(int a,int b);int main()int a,b;coutab;int fun1(int a,int b);int fun2(int a,int b);cout=1;i-)if(a%i=0&b%i=0)break;return i;int fun2(int a,int b)int n,j;n=a#includeusing namespace std;int main
6、()int m,i,s,x,n,j;coutx;coutn;s=0;for(i=0;i#includeusing namespace std;int fun(int a,int b);int main()int n,a,s,i,k;coutn;couta;s=0;for(i=0;i#includeusing namespace std;void main()int x,y,m,n,i,j=1,k=0,a20;coutm;y=m;cout0;i-) b=b/10;c=m/b;m=m-c*b;d+=c;cout#include using namespace std;int main()int m
7、,i;cout#include #include using namespace std;int main()double x1,x2,a,b;x2=0;x1=1.0;b=1.0;cina;while(b=1e-5)x2=(x1+a/x1)/2;b=fabs(x2-x1);x1=x2;cout#include #include using namespace std;int main()double x=1.5,x0,f,f1;dox0=x;f=2*x0*x0*x0-4*x0*x0+3*x0-6;f1=6*x0*x0-8*x+3;x=x0-f/f1;while(fabs(x-x0)=1e-5)
8、;coutusing namespace std;double fun(double x)return 2*x*x*x-4*x*x+3*x-6;double judge(double e,double a,double b)double c;c=(a+b)/2;if(b-ae;coutusing namespace std;int main()int i,j,k;for(i=1;iusing namespace std;int main()int x,y,z;int m=0;for(x=1;xusing namespace std;int main()int i,m,n=0;for(i=1;i
9、using namespace std;int main()int m,n,x;coutm;n=m%10;m=(m-n)/10;x=m%10;coutusing namespace std;int main()int a,b,c;coutabc;if(a+b)c&(a+c)b&(b+c)a&(a-b)#include using namespace std;int main()int a,b,c;coutabc;float x1,x2,d;d=sqrt(b*b-4*a*c);if(d=0)x1=(-b+d)/(2*a);x2=(-b-d)/(2*a);coutusing namespace s
10、td;int main()int s;couts;if(s100|s0&s=60&s=80&s=90&susing namespace std;int main()int year,month,day,days=0,i;coutyear;coutmonth;coutday;if(year10000|year13|day31)coutusing namespace std;long alldays(int year,int month,int day);long alldays(int year,int month,int day)int i;long d=0;for(i=1;i7)date=d
11、ate-7;coutusing namespace std;int main()int i;for(i=1;i+)if(i%3=2&i%5=3&i%7=2)break;else;coutusing namespace std;int main()int m1,m2,j=10,i,d=0,a20;coutm1;m2=m1;coutusing namespace std;int main()int i,n,s=0;coutn;for(i=1;iusing namespace std;int main()int i,n=1,m=3,s,s1=0,s2=0;for(i=1;ivoid main() i
12、nt a=1,b=-1,i,j; int m=1,n=1,sum=0; for(i=1;iusing namespace std;int main()int i,n,s=0,s1=0;cinn;for(i=1;iusing namespace std;int main()int i,n;cinn;for(i=n-1;i=1;i-)n*=i; coutusing namespace std;int main()int i,n,s=0,m=1;cinn;for(i=1;iusing namespace std;int main()int m,n=1,x=1,y=-1,sum=0;double a,
13、b=1,s=0;cinm;for(int i=1;iusing namespace std;int main()int m,i,n,s=0;cinn;for(i=1;iusing namespace std;int main()int n,i,m;cinn;for(i=2;i#include using namespace std;int main()int n,i,k,s=0,j=0;for(n=3;nk)cout#include using namespace std;int f(int x);int f(int a)/判断是否是素数int i,j;j=sqrt(a);for(i=2;ij
14、)return 1;else return 0;void main()int n,m,i,k;coutm;if(m#include using namespace std;void main()float i,n,s=0;for(i=1;i;i+)n=1/i;s+=n;if(fabs(s-8)#include using namespace std;void main()cout#include using namespace std;void main()int a,b,s,sum;for(a=1;a#include using namespace std;void main()int a,b,c,s=0,sum;for(a=1;a=100;a+)for(b=1;b=50;b+)for(c=1;c=20;c+)sum=a+2*b+5*c;if(sum=100)cout一分at;cout两分bt;cout五分ctendl;s+;cout共有s 种方法。endl;