December 23, 2024
Complementary DNA

Belajar Bahasa C – Complementary DNA

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;
}

Rajo Intan

Blogger, pemiliki Onestring Lab, menulis artikel terkait teknologi informasi dan pendidikan. Web Developer, berpengalaman lebih dari 20 tahun mengembangkan berbagai aplikasi dan sistem informasi. Kerjasama kontak di onestringlab@gmail.com atau https://forms.gle/xAGKkpi6B3BzJyzk7

View all posts by Rajo Intan →

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO