如何使用函数构建矩阵? [英] How do I using a function to build a matrix?
本文介绍了如何使用函数构建矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
/*I am a fish of C,I am writing a dynamic programming matrix for DNA alignment. */
#define p -0.005 /* the program is quite easy,just create a array first */
float f(int,int);
int main()
{
float table[6][6]; /*then fill the array with some fixed number*/
int x,y,i;
table[0][0]=p;
for(i=1;i<=5;i++)
table[i][0]=i*p;
for(i=1;i<=5;i++)
table[0][i]=i*p;
for(x=1;x<=5;x++) /* then fill the array,just using some comparings*/
for(y=1;y<=5;y++)
{
float a,b,c;
a=table[x-1][y-1]+f( x-1,y-1);
b=table[x][y-1]+p;
c=table[x-1][y]+p;
if(a>=b&&a>=c) table[x][y]=a;
if(b>=a&&b>=c) table[x][y]=b;
if(c>=b&&c>=a) table[x][y]=c;
}
for(x=0;x<=5;x++) /*finally print the number out*/
for(y=0;y<=5;y++)
{
printf("%.6f\t",table[x][y]);
if (y==5) printf("\n");
}
return 0;
}
float f(int x,int y)
{
char seq1[6],seq2[6];
float r;
seq1[6]="ACGTT";
seq2[6]="GCATG";
if (seq1[x]=='A'&&seq2[y]=='A'||seq1[x]=='T'&&seq2[y]=='T')
r=0.99;
if (seq1[x]=='G'&&seq2[y]=='G'||seq1[x]=='C'&&seq2[y]=='C')
r=0.99;
if(seq1[x]=='A'&&seq2[y]=='T'||seq1[x]=='T'&&seq2[y]=='A')
r=0.002;
if(seq1[x]=='A'&&seq2[y]=='G'||seq1[x]=='G'&&seq2[y]=='A')
r=0.006;
if(seq1[x]=='A'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='A')
r=0.002;
if(seq1[x]=='T'&&seq2[y]=='G'||seq1[x]=='G'&&seq2[y]=='T')
r=0.002;
if(seq1[x]=='T'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='T')
r=0.002;
if(seq1[x]=='G'&&seq2[y]=='C'||seq1[x]=='C'&&seq2[y]=='G')
r=0.006;
return(r);
}
然而,它只是不能用完。请帮助我!
however, it just can't run out.Help me please!
推荐答案
您的代码中存在此问题:
You have this problem in your code:
seq1[6]="ACGTT"; //You are assigning string to a single index.
seq2[6]="GCATG";
您可以这样写:
You can write like this:
char seq1[]="ACGTT",seq2[]="GCATG";
or
char seq1[]={'A','C','G','T','T'};
希望它能为您提供帮助。
Hope it will help you.
这篇关于如何使用函数构建矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文