Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

here: #include<stdio.h> #include <stdlib.h> #define MAX_IN_LENGTH 241 #define OU

ID: 3529412 • Letter: H

Question


here:

#include<stdio.h>

#include <stdlib.h>

#define MAX_IN_LENGTH 241

#define OUT_LENGTH 60

FILE *in;

FILE *out;

double compare_DNA(char [], char [], char s[], int );

void print_DNA(char [], char [], char [], int );

int read_DNA(char []);

int main()

{char s1[MAX_IN_LENGTH],s2[MAX_IN_LENGTH],s3[MAX_IN_LENGTH],ans[MAX_IN_LENGTH];

double percent;

int n,len;


in= fopen("dna_input.dat","r");

if(in==NULL) //is it ok?

{ printf("input file did not open please check it ");


return 1;

}

out= fopen("dna_output.dat","w");

len=read_DNA(s1);

len=read_DNA(s2);

len=read_DNA(s3);

fprintf(out,"Comparison between sequence # 1 and sequence #2: ");

percent=compare_DNA(s1,s2,ans,len);

print_DNA(s1,s2,ans,len);

fprintf(out,"The overlap percentage is %.1f%% ",percent*100);

fprintf(out,"Comparison between sequence # 1 and sequence #3: ");

percent=compare_DNA(s1,s3,ans,len);

print_DNA(s1,s3,ans,len);

fprintf(out,"The overlap percentage is %.1f%% ",percent*100);

fprintf(out,"Comparison between sequence # 2 and sequence #3: ");

percent=compare_DNA(s2,s3,ans,len);

print_DNA(s2,s3,ans,len);

fprintf(out,"The overlap percentage is %.1f%% ",percent*100);

fclose(in);

fclose(out);

return 0;

}

double compare_DNA(char seq1[], char seq2[], char seq3[], int n)

{int i,count=0;

for(i=0;i<n-1;i++)

{ if(seq1[i]==seq2[i])

{seq3[i]=seq1[i];

count++;

}

else

seq3[i]=' ';

}

return (double)count/(n-1);

}

void print_DNA(char seq1[], char seq2[], char seq3[], int n)

{int i=0,lines,j,start,stop;

lines=n/OUT_LENGTH;

if( n%OUT_LENGTH!=0)

lines++;

for(j=0;j<lines;j++)

{start=j*OUT_LENGTH;

stop=(j+1)*OUT_LENGTH;

if(stop>=n)

stop=n-1;

for(i=start;i<stop;i++)

fprintf(out,"%c",seq1[i]);

fprintf(out," ");

for(i=start;i<stop;i++)

{fprintf(out,"%c",seq3[i]);

if(seq3[i]==' ')

fprintf(out,"");

}

fprintf(out," ");

for(i=start;i<stop;i++)

fprintf(out,"%c",seq2[i]);

fprintf(out," ");

}

}

int read_DNA(char s[])

{int i;

fgets(s,MAX_IN_LENGTH,in);


for(i=0;i<MAX_IN_LENGTH;i++)

{if(s[i]=='')

return i;


}

return MAX_IN_LENGTH;

}




This below is the input:

Explanation / Answer

#include #include #define MAX_IN_LENGTH 241 #define OUT_LENGTH 60 FILE *in; FILE *out; double compare_DNA(char [], char [], char s[], int ); void print_DNA(char [], char [], char [], int ); int read_DNA(char []); int main() {chars1[MAX_IN_LENGTH],s2[MAX_IN_LENGTH],s3[MAX_IN_LENGTH],ans[MAX_IN_LENGTH]; double percent; int n,len; in= fopen("dna_input.dat","r"); if(in==NULL) //is it ok? { printf("input file did not open please checkit "); getch(); return 1; } out= fopen("dna_output.dat","w"); len=read_DNA(s1); len=read_DNA(s2); len=read_DNA(s3); fprintf(out,"Comparison between sequence # 1 and sequence #2: "); percent=compare_DNA(s1,s2,ans,len); print_DNA(s1,s2,ans,len); fprintf(out,"The overlap percentage is %.1f%% ",percent*100); fprintf(out,"Comparison between sequence # 1 and sequence #3: "); percent=compare_DNA(s1,s3,ans,len); print_DNA(s1,s3,ans,len); fprintf(out,"The overlap percentage is %.1f%% ",percent*100); fprintf(out,"Comparison between sequence # 2 and sequence #3: "); percent=compare_DNA(s2,s3,ans,len); print_DNA(s2,s3,ans,len); fprintf(out,"The overlap percentage is %.1f%% ",percent*100); fclose(in); fclose(out); return 0; } double compare_DNA(char seq1[], char seq2[], char seq3[], intn) {int i,count=0; for(i=0;i