700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > c语言求平方程序源代码 C语言求平方根源程序.docx

c语言求平方程序源代码 C语言求平方根源程序.docx

时间:2020-12-04 01:41:25

相关推荐

c语言求平方程序源代码 C语言求平方根源程序.docx

编程序求10000之内的完全平方数的平方根

#include main()

{

int a,b,d,e,f;

int A;

int i,j;

printf("\n\n***** 先把100以内的自然数打出来*****\n\n"); /*在Tc2.0下要注意把汉字改为英文 */

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

{ j=i*i;

printf(" %d*%d=%d ",i,i,j);

if(i%5==0)

printf("\n");

}

printf("\nPlsease enter a number:");

scanf("%d",&A);

while(A!=0) /* A是1到9999之间的任意一个完全平方数 */

{

if(A>=100)/* 对A分情况讨论 */

{ a=A/100; /* A除以100取整赋给a */

if(a>=1&&a<=3)

b=1;

if(a>=4&&a<=8)

b=2;

if(a>=9&&a<=15)

b=3;

if(a>=16&&a<=24)

b=4;

if(a>=25&&a<=35)

b=5;

if(a>=36&&a<=48)

b=6;

if(a>=49&&a<=63)

b=7;

if(a>=64&&a<=80)

b=8;

if(a>=81&&a<=99)

b=9;

}

if(A<100)

{ if(A==1)

{ b=1;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==4)

{ b=2;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==9)

{ b=3;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==16)

{ b=4;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==25)

{ b=5;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==36)

{ b=6;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==49)

{ b=7;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==64)

{ b=8;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

if(A==81)

{ b=9;

printf("\nthe root of A is %d",b);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

}

d=A-b*b*100; /* 变量b是第一次试商 */

e=d/(b*20); /* e 是第二次试商 */

if(e>=10)

e=e-1;

while(((b*20+e)*e)!=d)

e=e-1;

f=b*10+e;/* 变量f是所求平方根 */

printf("\nthe root of A is %d",f);

printf("\nPlsease enter a number:");

scanf("%d",&A);

}

}

此程序在VC++6.0 下编译运行通过,在Tc2.0也可以运行但要注意把汉字注释删除

运行结果如下

***** 先把100以内的自然数打出来*****

0*0=0

1*1=1 2*2=4 3*3=9 4*4=16 5*5=25

6*6=36 7*7=49 8*8=64 9*9=81 10*10=100

11*11=121 12*12=144 13*13=169 14*14=196 15*15=225

16*16=256 17*17=289 18*18=324 19*19=361 20*20=400

21*21=441 22*22=484 23*23=529 24*24=576 25*25=625

26*26=676 27*27=729 28*28=784 29*29=841 30*30=900

31*31=961 32*32=1024 33*33=1089 34*34=1156 35*35=1225

36*36=1296 37*37=1369 38*38=1444 39*39=1521 40*40=1600

41*41=1681 42*42=1764 43*43=1849 44*44=1936 45*45=2025

46*46=2116 47*47=2209 48*48=2304 49*49=2401 50*50=2500

51*51=2601 52*52=2704 53*53=2809 54*54=2916 55*55=3025

56*56=3136 57*57=3249 58*58=3364 59*59=3481 60*60=3600

61*61=3721 62*62=3844 63*63=3969 64*64=4096 65*65=4225

66*66=4356 67*67=4489 68*68=4624 69*69=4761 70*70=4900

71*71=5041 72*72=5184 73*73=5329 74*74=5476 75*75=5625

76*76=5776 77*77=5929 78*78=6084 79*79=6241 80*80=6400

81*81=6561 82*82=6724 83*83=6889 84*84=7056 85*85=7225

86*86=7396 87*87=7569 88*88=7744 89*89=7921 90*90=8100

91*91=8281 92*92=8464 93*93=8649 94*94=8836 95*95=9025

96*96=9216 97*97=9409 98*98=9604 99*99=9801

Plsease enter a number:4096

the root of A is 64

Plsease enter a number:7569

the root of A is 87

Plsease enter a number:4761

the root of A is 69

Plsease enter a number:5476

the root of A is 74

Plsease enter a number:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。