C PROGRAMING THANK YOU What is the output of the code fragme
C++ PROGRAMING. THANK YOU
What is the output of the code fragment below. Explain your answer. Char str[] = \"CTGAACTGCGTCATCAGTATGCGCATGCATCT\"; int n=0; while(str[n] !=\'\\0\') n +=1; int a=0; for (int i=0;iSolution
#include <iostream>
using namespace std;
int main()
{
char str[] = \"CTGAACTGCGTCATCAGTATGCGCATGCATCT\"; //Initializes a character array.
int n = 0; //Initializes n to 0. Loop variable.
while(str[n] != \'\\0\') //Starting from first character till the last character in the string str.
n += 1; //Everytime increment the n value.
//By now, n is the count of number of characters in the string.
int a = 0; //Initializes a to 0.
for(int i = 0; i < n; i++) //For each character in the string.
{
if(str[i] == 0x47 || str[i] == 65) //If the string character is either G or A. (These are the ASCII values 0x47 in hex representation of G, and 65 is decimal representation of A)
a++; //Increment the counter a.
}
cout<<a<<endl; //This prints the value of a. This program prints the total number of A\'s and G\'s in the specified string.
}
![C++ PROGRAMING. THANK YOU What is the output of the code fragment below. Explain your answer. Char str[] = \ C++ PROGRAMING. THANK YOU What is the output of the code fragment below. Explain your answer. Char str[] = \](/WebImages/6/c-programing-thank-you-what-is-the-output-of-the-code-fragme-989093-1761508409-0.webp)