本文主要是介绍C语言十字相乘法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
视频地址
初中数学九年级上 十字相乘法教程链接
//初学C语言第2天,2小时写了一个简单的穷举法。
#include<stdio.h>
#include<math.h>
int main()
{float a,b,c;a=2; //二次项系数b=5; //一次项系数c=-3; //常数项float a1,a2,a3,a4,c1,c2,c3,c4;for(a1=1;a1<=fabs(a);a1++) //a取整{a2=a/a1;a3=0-a1; //反数a4=a/a3; //反数for(c1=1;c1<=fabs(c);c1++) //c取整{c2=c/c1;c3=0-c1; //反数c4=c/c3; //反数if(a1*c2+a2*c1==b){printf("((%0.1f)X+(%0.1f))*((%0.1f)X+(%0.1f))=0\nX=%0.1f & %0.1f\n",a1,c1,a2,c2,(-c1)/a1,(-c2)/a2);}if(a1*c4+a2*c3==b){printf("((%0.1f)X+(%0.1f))*((%0.1f)X+(%0.1f))=0\nX=%0.1f & %0.1f\n",a1,c3,a2,c4,(-c3)/a1,(-c4)/a2);}if(a3*c2+a4*c1==b){printf("((%0.1f)X+(%0.1f))*((%0.1f)X+(%0.1f))=0\nX=%0.1f & %0.1f\n",a3,c1,a4,c2,(-c1)/a3,(-c2)/a4);}if(a3*c4+a4*c3==b){printf("((%0.1f)X+(%0.1f))*((%0.1f)X+(%0.1f))=0\nX=%0.1f & %0.1f\n",a3,c3,a4,c4,(-c3)/a3,(-c4)/a4);}}}return 0;
}
//输出
((1.0)X+(3.0))*((2.0)X+(-1.0))=0
X=-3.0 & 0.5
((-1.0)X+(-3.0))*((-2.0)X+(1.0))=0
X=-3.0 & 0.5
((2.0)X+(-1.0))*((1.0)X+(3.0))=0
X=0.5 & -3.0
((-2.0)X+(1.0))*((-1.0)X+(-3.0))=0
X=0.5 & -3.0
这篇关于C语言十字相乘法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!