I tried to write this C code to find complementary of DNA sequence. Please verify and help to improve.
#include<stdio.h>
main()
{
int n;
printf("\n\nEnter length of sequence:");
scanf("%d",&n);
char seq[n], com[n];
int i;
printf("\nENTER THE SEQUENCE:");
scanf("%s",&seq);
for(i;i<n;i++)
{
if(seq[i]=='A')
com[i]='T';
else if(seq[i]=='T')
com[i]='A';
else if(seq[i]=='G')
com[i]='C';
else if(seq[i]=='C')
com[i]='G';
else if(seq[i]==' ')
com[i]='_';
else if(seq[i]!='T' && seq[i]!='A' && seq[i]!='G' && seq[i]!='C')
com[i]='*';
}
printf("\n\n%s\n\n",com);
printf("\n\n* is non-DNA bases\n\n");
}
Inputting DNA sequence by hand.. very convenient.
we can copy paste it atleast................
Just for fun, I made a Python version of the script (outputs reverse complement):
A 1-liner might look like: