DOC

# lab7

By Ricky Howard,2014-11-02 16:15
15 views 0
lab7

1.

#include <stdio.h>

void main ()

{

int nnumber,ncount,i=0 ;

scanf("%d",&nnumber);

if(nnumber>=0&&nnumber<10000)

{

printf("该倒序为;\n");

while (nnumber!=0)

{

ncount=nnumber%10;

nnumber=nnumber/10;

i++;

printf("%d ",ncount);

}

printf("这是一个%d位数\n",i);

}

else

printf("error\n"); }

2.

#include<stdio.h>

void main ()

{

int nrandom,nnumber=0,ncount=0;

char cchar;

do

{

srand(time(NULL));

nrandom=rand()%100+1;//产生一个1~100的随机数

do

{

scanf("%d",nnumber);

if(nnumber>nrandom)

{

printf("too big\n");

}

if (nnumber=nrandom)

{

printf("congratulation! you are rigt !\n");

}

else

{

printf("too small");

}

ncount++;

}

while (nnumber!=nrandom);

printf(" a total of %d timis\n\n\n\n",ncount);

printf("Do you want to guss again?\n");

printf("A.yes B.no \n");

scanf("%c",cchar);

}

while (cchar!='B');

printf("Next time you are welcome to\n"); }

3.

#include<stdio.h>

#include<math.h>

void main()

{

double x1,x0,f,f1;

x1=1.5;

do

{

x0=x1;

f = 2*x0*x0*x0-4*x0*x0+3*x0-6;

f1=6*x0*x0-8*x0+3;

x1=x0-f / f1;//牛顿迭代公式 xn+1=xn-f(xn) / f '(xn)

}

while(fabs(x1-x0)>1e-6);

printf("the root of equation is %lf\n",x1);

}

4.

#include<stdio.h>

main( )

{

int ngn,nsn,nqn,nwn,nnumber;

scanf("%d",&nnumber);

nwn=nnumber/10000;

nqn=nnumber%10000/1000;

nsn=nnumber%100/10;

ngn=nnumber%10;

if (ngn==nwn&&nsn==nqn)/*个位等于万位并且十位等于千位*/

printf("this number is a huiwen\n");

else

printf("this number is not a huiwen\n");

}

5.

#include <stdio.h>

void main()

{

int k[10];

int i,j,n,s;

for(j=999;j>=2;j--)

{

n=-1;

s=j;

for(i=1;i <= j/2; i++)

{

if((j%i)==0)

{

n++;

s=s-i;

k[n]=i;

}

}

if(s==0)

{

printf("%d is a wanshu ",j);

for(i=0;i < 10; i++)

printf("%d ",k[i]);

printf("\n");

}

}

}

6.

Report this document

For any questions or suggestions please email
cust-service@docsford.com