资源描述:
《C语言求平方根源程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、编程序求10000之内的完全平方数的平方根#includemain(){inta,b,d,e,f;intA;inti,j;printf("*****先把100以内的自然数打出来*****");/*在Tc2.0下要注意把汉字改为英文*/for(i=0;i<100;i++){j=i*i;printf("%d*%d=%d",i,i,j);if(i%5==0)printf("");}printf("Plseaseenteranumber:");scanf("%d
2、",&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
3、&&a<=99)b=9;}if(A<100){if(A==1){b=1;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==4){b=2;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==9){b=3;printf("therootofAis%d",b);pri
4、ntf("Plseaseenteranumber:");scanf("%d",&A);}if(A==16){b=4;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==25){b=5;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==36){b=6;printf
5、("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==49){b=7;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d",&A);}if(A==64){b=8;printf("therootofAis%d",b);printf("Plseaseenteranumber:");scanf("%d"
6、,&A);}if(A==81){b=9;printf("therootofAis%d",b);printf("Plseaseenteranumber:");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("therootofAis%d",f);printf("
7、Plseaseenteranumber:");scanf("%d",&A);}}此程序在VC++6.0下编译运行通过,在Tc2.0也可以运行但要注意把汉字注释删除运行结果如下*****先把100以内的自然数打出来*****0*0=01*1=12*2=43*3=94*4=165*5=256*6=367*7=498*8=649*9=8110*10=10011*11=12112*12=14413*13=16914*14=19615*15=22516*16=25617*17=28918*18=32419
8、*19=36120*20=40021*21=44122*22=48423*23=52924*24=57625*25=62526*26=67627*27=72928*28=78429*29=84130*30=90031*31=96132*32=102433*33=108934*34=115635*35=122536*36=129637*37=136938*38=144439*39=152140*40=160041*41=168142*42=176443*43=184944*44=193645*45