1、1 2 11 3 3 1.#include using namespace std;int main()int i =1 , sum = 0 ;dosum = sum + i;i+;while (i=100);cout “sum=”sum=a &c=A&=Z) c=c+4; if(cZ & cz)c=c-26; c; endl;return 0;3int main ()char c; int letters=0,space=0,digit=0,other=0; couta &z|cAZ letters+; else if (c= space+; else if (c09 digit+; els
2、e other+;letter:letters, space:space, digit:digit, other:otheran; while (i=n) tn=tn+a; /赋值后的tn为i个a组成数的值 sn=sn+tn; /赋值后的sn为多项式前i项之和 a=a*10; +i;a+aa+aaa+.=sn5float s=0,t=1; int n; for (n=1;n=20;n+) t=t*n; / 求n! s=s+t; / 将各项累加 1!+2!+.+20!=s6int i,j,k,n;narcissus numbers are: for (n=100;1000; i=n/100; j
3、=n/10-i*10; k=n%10; if (n = i*i*i + j*j*j + k*k*k) 7 int m,s,i; for (m=2;mm+) s=0; for (i=1;im;i+) if (m%i)=0) s=s+i; if(s=m) cout is a完数its factors are: if (m%i=0) cout0) x1=(x2+1)*2; / 第1天的桃子数是第2天桃子数加1后的2倍 x2=x1; day-;total=x1 float a,x0,x1;enter a positive number:a; / 输入a的值 x0=a/2; x1=(x0+a/x0)/2
4、; do x0=x1; while(fabs(x0-x1)=1e-5);The square root of a is 11 int i,k; for (i=0;=3;i+) / 输出上面4行*号 for (k=0;k=2*i;k+)* / 输出*号 /输出完一行*号后换行 =2;i+) / 输出下面3行*号 =4-2*i; / 输出完一行*号后换行12long fac(int); /函数声明int main( ) /n为需要求阶乘的整数 long y; /y为存放n!的变量please input an integer :; /输入的提示 /输入n y=fac(n); /调用fac函数以求n
5、!=y /输出n!的值long fac(int n) /递归函数 long f; if(nn0,data error!1时,进行递归调用 return f; /将f的值作为函数值返回13 int hcf(int,int); int lcd(int,int,int); int u,v,h,l;uv; h=hcf(u,v);H.C.F=h l=lcd(u,v,h);L.C.D=lu) t=u;u=v;v=t; while (r=u%v)!=0) u=v; v=r; return(v);int lcd(int u,int v,int h) return(u*v/h);14math.hfloat x1
6、,x2,disc,p,q;void greater_than_zero(float,float); void equal_to_zero(float,float); void smaller_than_zero(float,float); float a,b,c;input a,b,c:b disc=b*b-4*a*c;root: if (disc greater_than_zero(a,b);x1=,x2=x2 else if (disc=0) equal_to_zero(a,b); smaller_than_zero(a,b);p+q0时方程的根 */ x1=(-b+sqrt(disc)/
7、(2*a); x2=(-b-sqrt(disc)/(2*a);void equal_to_zero(float a,float b) /* 定义一个函数,用来求disc=0时方程的根 */ x1=x2=(-b)/(2*a);void smaller_than_zero(float a,float b) /* 定义一个函数,用来求disc p=-b/(2*a); q=sqrt(-disc)/(2*a);15 int prime(int); /* 函数原型声明 */input an integer: if (prime(n) is a prime. is not a prime. int prim
8、e(int n) int flag=1,i; for (i=2;n/2 & flag=1; if (n%i=0) flag=0; return(flag);16 int fac(int); int a,b,c,sum=0;enter a,b,c: sum=sum+fac(a)+fac(b)+fac(c);!b int fac(int n) int f=1; for (int i=1; f=f*i;17void godbaha(int);input n: godbaha(n);void godbaha(int n) int prime(int); int a,b; for(a=3;=n/2;a=
9、a+2) if(prime(a) b=n-a; if (prime(b) coutk) return 1; else return 0;18int f(int); int n,s;input the number n: s=f(n);The result is int f(int n) ; if (n=1) return 1; return (n*n+f(n-1);19#include int i; int f20=1,1;20; fi=fi-2+fi-1; for(i=0; if(i%5 = 0) cout cout setw(8)fi;20 int a10;int i,j,t;”input
10、 10 numbers:” for(i=0;jai+1) t=ai;ai=ai+1;ai+1=t;”the sorted numbers:10;ai” ”;21int a23=1,2,3,4,5,6;int b32,I,j; “array a:”,endl; for(j+0; cout a ijmax) max=aij; row=i; colum=j;”max=”max”,row=“row”,colum=”colum23void selet_sort(int array,int n); int a10,i;”enter the originl array:for (i=0;ai;coutsel
11、et_sort(a,10); “the sorted array:endl:void selet_sort(int array,int n)int i,j,k;fot (i=0;n-1; k=i; for(j=i+1; if(arrayjarrayk)k=j;t=arrayk;arrayk=arrayi;arrayi=t;24/#include int i,j,min,temp,a11;enter data:=10;a= /输入10个数 endlaj) min=j; temp=ai; /以下3行将ai+1a10中最小者与ai 对换 ai=amin; amin=temp;The sorted numbers:i+) / 输出已排好序的10个数 25 int a33,sum=0; int i,j;3; for (j=0;aij; sum=sum+aii;26 const int n=11; int i,j,ann; aii=1; ai1=1; for (i=3; for (j=2;=i-1; aij=ai-1j-1+ai-1j; for (
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1