usingnamespacestd;intfn1(inti,intj);//求最大公约数的函数voidmain(){inti,j,x,y;cout<<"请输入一个正整数:";cin>>i;cout<<"请输入另一个正整数:";cin>>j;x=fn1(i,j);y=i*j/x;cout<2、endl;}intfn1(inti,intj){inttemp;if(ivoidmain(){charc;intletters=0,space=0,digit=0,other=0;printf("请输入一行字符:");while((c=getchar())!=''){if(c>='a'&&c<='z'
3、
4、
5、c>='A'&&c<='Z')letters++;elseif(c=='')space++;elseif(c>='0'&&c<='9')digit++;elseother++;}printf("字母数:%d空格数:%d数字数:%d其它字符数:%d",letters,space,digit,other);}4.求1!+2!+3!+4!+。。。。+20!#includevoidmain(){doubles=0,t=1;intn;for(n=1;n<=20;n++){t=t*n;s=s+t;}pr
6、intf("1!+2!+...+20!=%lf",s);}5求∑K(k从1到100)+∑k2(从1到50)+∑1/k(从1到10)#includevoidmain(){intn1=100,n2=50,n3=10;doublek,s1=0,s2=0,s3=0;for(k=1;k<=n1;k++)/*计算到的和*/{s1=s1+k;}for(k=1;k<=n2;k++)/*计算到各数的平方和*/{s2=s2+k*k;}for(k=1;k<=n3;k++)/*计算到的各倒数和*/{s3=s3+1/k;}printf
7、("sum=%15.6f",s1+s2+s3);}6.输出所有的水仙花数,所谓水仙花数就是指一个3位数,其各位数字立方和等于该数本身。#includevoidmain(){inti,j,k,n;printf("parcissusnumbersare");for(n=100;n<1000;n++){i=n/100;j=n/10-i*10;k=n%10;if(n==i*i*i+j*j*j+k*k*k)printf("%d",n);}printf("");}7有一分数序列2/1,3/2,5/3,8/5,13/8
8、,21/13….求出这个数列的前20项之和#includevoidmain(){inti,n=20;doublea=2,b=1,s=0,t;for(i=1;i<=n;i++){s=s+a/b;t=a,a=a+b,b=t;}printf("sum=%16.10f",s);}8.用筛选法求100之内的素数#include#includevoidmain(){inti,j,n,a[101];for(i=1;i<=100;i++)a[i]=i;a[1]=0;for(i=2;i9、t(100.0000);i++)for(j=i+1;j<=100;j++){if(a[i]!=0&&a[j]!=0)if(a[j]%a[i]==0)a[j]=0;}printf("");for(i=2,n=0;i<=100;i++){if(a[i]!=0){printf("%5d",a[i]);n++;}if(n==10){printf("");n=0;}}printf("");}9.用选择法对10个整数排序#includevoidmain(){inti,j,min,temp,a[11];printf
10、("请依次输入个数:");for(i=1;i<=10;i++){printf("a[%d]=",i);scanf("%d",&a[i]);}printf("");printf("你输入的个数据为:");for(i=1;i<=10;i++