IN C++ PLEASE Suppose we are interested in studying a DNA sequence which consist
ID: 3724092 • Letter: I
Question
IN C++ PLEASE
Suppose we are interested in studying a DNA sequence which consists of four bases: A, C, G, and T. For example TGCGTGCTACCACATCATGCAGTTTTCAAAGAAGAAAGCCTCACCACAAA. Your goal is to compute the occurrence (expressed as a percentage) of each base and output it in the following format (including the header): Base Statistics A: 26.4 C: 44.1 G: 34.8 T: 13.6 Constraints The DNA sequence can be from 1 to 50 characters long · In order to output floating point numbers with only one decimal digit, you may use %.1r .You must read the DNA sequence input from the user Example 1 13.19.1: Arrays - Ex3 LAB 0/16 dna.c Load default template... 1 #include int nain) ( 5 Type your code here. * return ;Explanation / Answer
#include <stdio.h>
int main() {
char s[51];
int i=0, a=0, c=0, g=0, t=0, total;
scanf("%s", s);
while(s[i]) {
if(s[i] == 'A') {
a++;
} else if(s[i] == 'C') {
c++;
} else if(s[i] == 'G') {
g++;
} else if(s[i] == 'T') {
t++;
}
i++;
}
total = a+c+g+t;
printf("Base Statistics ");
printf("A: %.1f ", a*100/(float)total);
printf("C: %.1f ", c*100/(float)total);
printf("G: %.1f ", g*100/(float)total);
printf("T: %.1f ", t*100/(float)total);
return 0;
}