Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the “instructions” for the development and functioning of living organisms.
If you want to know more: http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols “A” and “T” are complements of each other, as “C” and “G”. Your function receives one side of the DNA (string, except for Haskell); you need to return the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).
More similar exercise are found here: http://rosalind.info/problems/list-view/ (source)
Example: (input –> output)
"ATTGC" --> "TAACG"
"GTAT" --> "CATA"
The problem link is here.
Solution:
#include <string.h>
char *dna_strand(const char *dna)
{
int len = strlen(dna);
int i;
char *cdna = calloc(len + 1, sizeof(char));
char temp;
strcpy(cdna, "");
for (i = 0; i < len; i++)
{
if (dna[i] == 'A')
{
temp = 'T';
strncat(cdna, &temp, 1);
}
else if (dna[i] == 'T')
{
temp = 'A';
strncat(cdna, &temp, 1);
}
else if (dna[i] == 'C')
{
temp = 'G';
strncat(cdna, &temp, 1);
}
else if (dna[i] == 'G')
{
temp = 'C';
strncat(cdna, &temp, 1);
}
}
return cdna;
}