• 判断非齐次方程组是否有解 c++


    #include <iostream>
    using namespace std;

    int main()
    {
    double a[] ={2,2,2,
    3,2,4,
    1,3,9};

    double b[] = {1,0.5,2.5};
    double m =0;
    int n=3;

    for (int i = 0; i < n-1; i++)
    {
    for (int j = i + 1; j < n; j++)
    {
    m = a[j*n+i] / a[i*n+i];
    b[j] = b[j] - m * b[i];
    for (int k = i; k < n; k++)
    {
    a[j*n+k] = a[j*n+k] - m*a[i*n+k];
    }
    }
    }

    int deta=0;
    int detb=0;

    for (int i=0;i<n;i++)
    {
    if (b[i] == 0)
    {
    detb = i-1;
    break;
    }
    }
    if (detb ==0)
    {
    detb =2;
    }

    int tmp=0;
    for (int i=0;i<n;i++)
    {
    for (int j=0;j<n;j++)
    {
    if (a[i*n+j] == 0 )
    {
    tmp++;
    }
    }
    if (tmp == n)
    {
    deta = i-1;
    break;
    }
    tmp =0;
    }

    if (tmp ==0)
    {
    deta=2;
    }

    for (int i=0;i<n;i++)
    {
    for (int j=0;j<n;j++)
    {
    cout<<a[i*n+j]<<"";
    }
    cout<<endl;
    }

    cout<<endl;
    for (int i=0;i<n;i++)
    {
    cout<<b[i]<<"";
    }
    cout<<endl;
    cout<<deta<<""<<detb<<endl;

    if (deta < detb)
    {
    cout<<"no exit solution"<<endl;
    }
    else
    {
    cout<<"exit solution"<<endl;
    }

    system("pause");
    return 0;
    }
  • 相关阅读:
    poj 1562 Oil Deposits
    poj 1650 Integer Approximation
    snmp4j 编程
    ubuntu 13.04 163源(亲测可用)
    c语言中static 用法总结(转)
    Spring入门
    Hibernate入门
    Struts2入门教程
    素数距离问题
    ASCII码排序
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2277266.html
Copyright © 2020-2023  润新知