#include <stdio.h>
#include <math.h>
#include <string.h>
void x6(){
double sum=0,n=1;
int i;
for(i=1;i<=20;i++){
n*=i;
sum+=n;
}
printf("%e\n",sum);
}
void x8(){
int q,w,e,r=100;
while(r<1000){
q=r%10;
w=r/10%10;
e=r/100%10;
if(pow(q,3)+pow(w,3)+pow(e,3)==r)
printf("%d ",r);
r++;
}
putchar('\n');
}
void x9(){
int n,k,sum;
int i=1;
while(i<=1000){
k=1;n=0;sum=0;
while(i>k){
if(i%k==0)
sum+=k;
k++;
}
if(i==sum)
{
printf("%d its factors are ",i);
k=1;
while(i>k){
if(i%k==0)
printf("%d ",k);
k++;
}
printf("\n");
}
i++;
}
}
void x10(){
double x=2,y=1,sum=0,t;
int i=0;
while(i<20){
sum+=x/y;
t=x;
x+=y;
y=t;
i++;
}
printf("前20项之和为:%.12f\n",sum);
}
void x11(){
double h=100;
int k=1;
while(k<=10){
h/=2;
k++;
}
printf("第十次还有%f米高!\n",h);
}
void x12(){
int x=1,k=1,n;
while(k<10)
{
x=(x+1)*2;
k++;
}
printf("共摘了%d个桃子!\n",x);
}
void x13(){
float x1,x2,a;
printf("请输入要平方的值:\n");
scanf("%f",&a);
x1=sqrt(a);
do{
x2=(x1+a/x1)/2;
x1=x2;
}while(fabs(x2-x1)>=pow(10,-5));
printf("a=%f\nx2=%f\n",a,x2);
}
void x14(){
double x0,x1,f1,f2;
x1=1.5;
do{
x0=x1;
f1=((2*x0-4)*x0+3)*x0-6;
f2=(6*x0-8)*x0+3;
x1=x0-f1/f2;
}while(fabs(x1-x0)>pow(10,5));
printf("根为:%f\n",x1);
}
void x15(){
float x0,x1,x2,fx0,fx1,fx2;
do{
printf("enter x1 and x2:\n");
scanf("%f%f",&x1,&x2);
fx1=x1*((2*x1-4)*x1+3)-6;
fx2=x2*((2*x2-4)*x2+3)-6;
}while(fx1*fx2>0);
do{
x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6;
if((fx0*fx1)<0){
x2=x0;
fx2=fx0;
}
else{
x1=x0;
fx1=fx0;
}
}while(fabs(fx0)>=pow(10,-5));
printf("x=%6.2f\n",x0);
}
void x16(){
printf("请输入您要打印图案最多一行*的个数:\n");
int i,j,k;
for(i=0;i<=3;i++)
{
for(j=0;j<=2-i;j++)
printf(" ");
for(k=0;k<=2*i;k++)
printf("*");
printf("\n");
}
for(i=0;i<=2;i++)
{
for(j=0;j<=i;j++)
printf(" ");
for(k=0;k<=4-2*i;k++)
printf("*");
printf("\n");
}
}
void x17(){
char a,b,c;
for(a='x';a<='z';a++)
for(b='x';b<='z';b++)
if(a!=b)
for(c='x';c<='z';c++)
if(a!=c&&b!=c)
if(a!='x'&&c!='x'&&c!='z')
printf("A的对手是:%c\nB的对手是:%c\nC的对手是:%c\n",a,b,c);
}
int main(){
int ch;
scanf("%d",&ch);
switch(ch){
case 6:x6();
break;
case 8:x8();
break;
case 9:x9();
break;
case 10:x10();
break;
case 11:x11();
break;
case 12:x12();
break;
case 13:x13();
break;
case 14:x14();
break;
case 15:x15();
break;
case 16:x16();
break;
case 17:x17();
break;
default:printf("这道题没做哦,你可以试试其它的!\n");
}
return 0;
}
还是老规矩,大家直接运行,输入相应的题号,就会执行相应的程序哦!
|