in c++ language please Summary given 2 DNA strands of equal length, compare the
ID: 3872886 • Letter: I
Question
in c++ language please
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// declaring variables
string a, b;
int count = 0;
// taking user input
cout << "Enter DNA 1: ";
cin >> a;
cout << "Enter DNA 2: ";
cin >> b;
// printing first strand
cout << endl << a << endl;
// looping through each character
for(int i=0;i<a.length();i++)
{
// checking if they are equal
if(a[i]==b[i])
cout << " ";
// if not, increasing count by 1 and printing X
else
{
count++;
cout << "X";
}
}
// printing second strand
cout << endl << b << endl;
cout << "**Differences: " << count << endl;
}
SAMPLE OUTPUT
#include <iostream>
using namespace std;
int main() {
// declaring variables
string a, b;
int count = 0;
// taking user input
cout << "Enter DNA 1: ";
cin >> a;
cout << "Enter DNA 2: ";
cin >> b;
// printing first strand
cout << endl << a << endl;
// looping through each character
for(int i=0;i<a.length();i++)
{
// checking if they are equal
if(a[i]==b[i])
cout << " ";
// if not, increasing count by 1 and printing X
else
{
count++;
cout << "X";
}
}
// printing second strand
cout << endl << b << endl;
cout << "**Differences: " << count << endl;
}
SAMPLE OUTPUT
Enter DNA 1: CCATGGTC Enter DNA 2: CCAGTGAC CCATGGTC XX X CCAGTGAC **Differences: 3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.