| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1543 人关注过本帖
标题:求行列式
只看楼主 加入收藏
藏龙1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-5
收藏
 问题点数:0 回复次数:8 
求行列式
请问
求行列式的值的C程序怎么写
我是超级低手 请各位高手给个答案
搜索更多相关主题的帖子: 行列式 
2008-11-06 10:24
cfans1314
Rank: 1
等 级:新手上路
帖 子:54
专家分:0
注 册:2008-10-20
收藏
得分:0 
好好学c
发帖时,尽量要具体,你这样别人那有空给你弄呢!
  ......祝你好运!
2008-11-06 10:53
藏龙1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-5
收藏
得分:0 
谢谢 下次知道了
2008-11-06 21:14
藏龙1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-5
收藏
得分:0 
谢谢 下次知道了
2008-11-06 21:15
tanlinghang
Rank: 1
来 自:四川大学
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-11-1
收藏
得分:0 
#include "stdio.h"
#define num 3
void main()
{
    float permutation(float det[num][num],int m,int two[num],float sum);  /*申明全排列函数*/
    int sign(int two[num]);                                          /*申明符号函数*/
    int i,j,k,two[num];
    float det[num][num],sum=0;
    for(k=0;k<num;k++)
    {
        two[k]=k;                  /*为二维变量赋值*/
    }
    for(i=0;i<num;i++)
     for(j=0;j<num;j++)
      {
          printf("Please input the number of det %d-%d:",i+1,j+1);
        scanf("%f",&det[i][j]);
      }
    sum=permutation(det,0,two,sum);        /*调用全排列函数*/
    printf("The result of the det is %f.",sum);
}
float permutation(float det[num][num],int m,int two[num],float sum)    /*定义全排列函数*/
{
    int a,count,c;
    float t,mul=1;
    if(m<num-1)
    {
        sum=permutation(det,m+1,two,sum);         /*调用全排列函数*/
        for(a=m+1;a<num;a++)
        {
            t=two[m];two[m]=two[a];two[a]=t;
            sum=permutation(det,m+1,two,sum);        /*调用全排列函数*/
            t=two[m];two[m]=two[a];two[a]=t;
        }
    }
    else
    {
        for(count=0;count<num;count++)
        {
            mul=mul*det[count][two[count]];
        }
        c=sign(two);                         /*调用符号函数*/
        if(c==0)
        {
            sum=sum+mul;
        }
        else
        {
            sum=sum-mul;
        }
    
    }
    return(sum);
}
int sign(int two[num])                          /*定义符号函数*/
{
    int count_num=0,y,z,c;
    for(y=0;y<num;y++)
     for(z=y+1;z<num;z++)
     {
         if(two[y]>two[z])
         count_num++;
     }
    if(count_num%2==0)
     c=0;
    else
     c=1;
    return(c);
}

以上代码经过我的些许测试是正确的,我现在大一,也在学行列式,看见这个帖子就很感兴趣,所以昨天到今天都在想这个程序,毕竟刚开始学C语言。其中permutation函数是类全排列函数,我昨天在论坛上问了前辈才知道全排列的,不然根本就写不出,我改了一下,将类似全排列的函数加入了这个程序。
程序第2行是宏的定义,num后的数字可以更改,代表num阶行列式···
因为C语言还没学完,编不出输入阶数后自动运行的程序,需要手动修改常量,这点望前辈指教。
本代码也只支持整数或者小数的行列式运算,无法带参数····

Only by standing on the shoulder of the giant can I see farther and farther.
2008-11-07 11:47
藏龙1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-5
收藏
得分:0 
同志啊 我也是大一的  喜欢编程  不过刚起步 幸好遇见兄弟你啊
2008-11-07 13:10
藏龙1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2008-11-5
收藏
得分:0 
兄弟 你在定义全排列函数的时候好象用到了符号函数 但没声明
2008-11-07 13:40
tanlinghang
Rank: 1
来 自:四川大学
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-11-1
收藏
得分:0 
···好像是没申明来着  但我运行通过了···不过我在主函数里申明了 ··我去看看书 需要申明不···我感觉还是申明好些 至少增加可读性

Only by standing on the shoulder of the giant can I see farther and farther.
2008-11-07 21:13
快速回复:求行列式
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011835 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved