2、ntmain(){intm,n;printf("请输入两个整数:");scanf("%d%d",&m,&n);printf("%d与%d的最大公约数是:%d",m,n,f1(m,n));printf("%d与%d的最小公倍数是:%d",m,n,f2(m,n));return0;}结论:结果正确。实验二:方程根的求解,源程序如下:#include#includedoublef1(floatm,floatn,floatq){doubler,x1,x2;r=n*n-4*m*q;if(m==0)x1
3、=-q/n,printf("方程有唯一实根:%lf",x1);elsex1=(-n+sqrt(r))/(2*m),x2=(-n-sqrt(r))/(2*m),printf("方程有两个不等的实根:%lft%lf",x1,x2);return0;}doublef2(floatm,floatn,floatq){doublex1;if(n!=0)x1=-n/(2*m),printf("方程有两个相等实根:%lf",x1);elseif(q==0)printf("方程的根为任意数");elseprintf("方程无解"
4、);return0;}doublef3(floatm,floatn,floatq){doubler,p,d;r=n*n-4*m*q;p=sqrt(-r)/(2*m),d=-n/(2*m);printf("方程有两个复根:");printf("%lf+%lfit",d,p);printf("%lf-%lfi",d,p);return0;}intmain(){floatr,a,b,c;printf("请输入方程的系数:");scanf("%f%f%f",&a,&b,&c);r=b*b-4*a*c;if(r>0)f1(a,b,c);
5、if(r==0)f2(a,b,c);if(r<0)f3(a,b,c);return0;}结论:结果正确。实验三:回文的判断和输出及统计其个数,源程序如下:#include#include#defineN100charf(charc[]){inti,j,n;for(i=0,n=0;c[i]!=' ';i++)n++;for(i=0,j=n-1;i6、("请输入五个字符串:");for(i=0;i<5;i++)gets(a[i]);printf("其中回文是:");for(i=0,j=0;i<5;i++)if(f(a[i])==1){printf("%s",a[i]);j++;}printf("回文有%d个",j);return0;}结论:结果正确。实验四:数组的降序输出,源程序如下:#include#defineN10voidsort(inta[],intn){inti,j,t;for(i=1;i7、)if(a[j]intf(intn){inti,k=
8、0;for(i=1;i