use C program Deoxyribonucleic acid (DNA) is composed of two complementary base strands combined in a double helix. There are four bases that make up DNA, namely adenine (A), guanine (G), thymine (T) and cytosine (C). At the corresponding positions of the two complementary base strands, adenine always pairs with thymine, and guanine always pairs with cytosine. Your task is to give the base sequence on the corresponding complementary strand based on the base sequence on a single strand. [Input] The first line is a positive integer n, indicating that there are n base chains to be solved. There are a total of n lines below, and each line uses a string to represent a base chain. This string contains only capital letters A, T, G, C, which represent adenine, thymine, guanine, and cytosine, respectively. The length of each base chain does not exceed 255. [Output] There are n lines in total, and each line contains only uppercase letters A, T, G, and C. are the base strands complementary to each of the input base strands, respectively.
时间: 2024-02-28 19:57:53 浏览: 81
Sure, here's a C program that accomplishes the task you described using string manipulation:
```C
#include <stdio.h>
#include <string.h>
int main() {
int n, i, j;
// Input the number of base chains
printf("Enter the number of base chains: ");
scanf("%d", &n);
// Input the base chains and output their complementary strands
for (i = 0; i < n; i++) {
char s[256];
printf("Enter base chain %d: ", i+1);
scanf("%s", s);
for (j = 0; j < strlen(s); j++) {
switch (s[j]) {
case 'A':
printf("T");
break;
case 'T':
printf("A");
break;
case 'G':
printf("C");
break;
case 'C':
printf("G");
break;
}
}
printf("\n");
}
return 0;
}
```
You can compile and run this code to test it out.
阅读全文