I Year C Programming Lab

Download as pdf or txt
Download as pdf or txt
You are on page 1of 57

VELLALAR COLLEGE FOR WOMEN (Autonomous), ERODE-12

“College with Potential For Excellence”


(Re-Accredited by NAAC with Grade ‘A’ & Affiliated to Bharathiar University, Coimbatore-46.)

DEPARTMENT OF COMPUTER SCIENCE (UG & PG)

CORE PRACTICAL

C PROGRAMMING - LAB

RECORD NOTE BOOK

DECEMBER-2021

Register No : ______________

Class : _______________

CERTIFICATE

Certified bonafide record of practical work done by __________________________

Head of the Department College Seal Staff-in-charge

Date:

Submitted for the Practical Examination held on _____________ at Vellalar College


for Women (Autonomous), Erode-12.

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

PAGE
S.NO DATE CONTENT SIGNATURE
NO

CALCULATION OF SUM, AVERAGE AND


1 STANDARD DEVIATION

DECIMAL TO BINARY CONVERSION


2

BINOMIAL COEFFICIENT nCr USING


3 FUNCTION

MATRIX MULTIPLICATION
4

5 PRINTING FIBONACCI NUMBERS

6 BINARY SEARCH

7 VOWELS AND CONSONANTS

8 PERMUTATION OF A STRING

9 PHYSICAL FITNESS CRITERIA

HALLOW SQUARE STAR PATTERN


10

11 STUDENT MARKSHEET

COMPLEMENTARY SEQUENCE AND


12 PERCENTAGE OF NUCLEOTIDES IN A DNA
Write a C program to find the sum, average and standard deviation for a given set of numbers.
Ex.No : 1 CALCULATION OF SUM, AVERAGE AND STANDARD DEVIATION

Aim:

To find the sum, average and standard deviation for a given set of numbers.

Algorithm:

Step 1: Start the process.

Step 2: Get the number of values for which the sum, average and standard deviation is to

be calculated.

Step 3: Get the value one by one, add the values and store the result in sum.

Step 4: Calculate the average value using the formula.

Average=sum of values/Total number of values.

Step 5: Calculate the standard deviation value using the formula

Step 6: Print the value of sum, average and standard deviation.

Step 7: Stop the process


Program

#include<stdio.h>
#include<curses.h>
#include<math.h>
void main()
{
int i,x,n,sum=0,sum1=0;
float avg,var,std;
printf("\n\n\t CALCULATION OF SUM AVERAGE AND STANDARD
DEVIATION\n");
printf("\n Enter n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\n Enter x value:");
scanf("%d",&x);
sum=sum+x;
sum1=sum1+x*x;
}
avg=(float)sum/n;
var=(float)sum1/n-avg*avg;
std=(float)var;
printf("\n sum is %d",sum);
printf("\n average is %4.2f",avg);
printf("\n std.deviation is %4.2f",std);
}
Output

CALCULATION OF SUM AVERAGE AND STANDARD DEVIATION

Enter n value:5

Enter x value:10

Enter x value:20

Enter x value:30

Enter x value:40

Enter x value:50

sum is 150

average is 30.00

std.deviation is 200.00

Result

The above program is successfully executed and verified.


Write a C Program to convert a decimal number into binary.
Ex. No : 2 DECIMAL TO BINARY CONVERSION

Aim:

To convert a decimal number into its binary number.

Algorithm:

Step 1: Start the process.

Step 2: Get the decimal number which is to be converted to this equivalent binary
number.

Step 3: Using while and for loop perform the conversion.

Step 4: Print the result.

Step 5: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
void main()
{
int dec,quo;
int bin [100],j,i=1;
printf("\n\n\t\t DECIMAL TO BINARY CONVERSION");
printf("\n\n\t\t ***********************************");
printf("\n Enter decimal value:");
scanf("%d",&dec);
quo=dec;
while(quo!=0)
{
bin[i++]=quo%2;
quo=quo/2;
}
printf("\n The binary value for %d is ",dec);
for(j=i-1;j>0;j--)
{
printf("%d",bin[j]);
}
}
Output

DECIMAL TO BINARY CONVERSION


**********************************

Enter decimal value:11

The binary value for 11 is 1011

Result

The above program is successfully executed and verified.


Calculate the binomial coefficient nCr using functions.
Ex.No : 3 BINOMIAL COEFFICIENT nCr USING FUNCTION

Aim:

To calculate the binomial coefficient nCr using functions.

Algorithm:

Step 1: Start the process.

Step 2: Declare necessary functions initially.

Step 3: Get the values for n and c.

Step 4: Calculate the binomial coefficient value from n and r using the formula.

n!/r!(n-r)!

Step 5: The factorial values are calculated by calling the necessary functions.

Step 6: Print the binomial coefficient value.

Step 7: Stop the process.


Program

#include<stdio.h>
long int factorial(int);
main()
{
long int n,r,ncr;
printf("\n\t\tBINOMIAL COEFFICIENT nCr USING FUNCTIONS");
printf("\n\t\t****************************************");
printf("\nEnter the value for n:");
scanf("%ld",&n);
printf("\n Enter the value for r:");
scanf("%ld",&r);
ncr=factorial(n)/(factorial(r)*factorial(n-r));
printf("\n The factorial of given number is :%ld\n",ncr);
}
long int factorial (int n)
{
long int fact ;
if((n==0)||(n==1))
return(1);
else
fact =n*factorial(n-1);
return(fact);
}
Output

BINOMIAL COEFFICIENT nCr USING FUNCTIONS


**********************************************
Enter the value for n:9

Enter the value for r:6

The factorial of given number is :84

Result

The above program is successfully executed and verified.


Write a C Program to multiply two matrix using function.
Ex.No : 4 MATRIX MULTIPLICATION

Aim:

To perform matrix multiplication two matrix using function.

Algorithm:

Step 1: Start the process.

Step 2: Declare the required variables and functions.

Step 3: In main() function, call the read(), mult() and display().

Step 4: In read() get the dimension for a and b matrix.

Step 5: Check whether the dimensions are valid for performing matrix multiplication.

Step 6: Check whether the dimensions are not valid. print the error message else if

dimensions are valid, proceed the multiple process.

Step 7: In mult() function, multiply the given two matrix.

Step 8: In display(), display the two matrices and result the matrices.

Step 9: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
int a[5][5],b[5][5],c[5][5],x[5][5];
int m,n,p,q,r,s,i,j,k,sum=0;
void read();
void mult();
void display();
void main()
{
printf("\n\t MATRIX MULTIPLICATION\n");
read();
}
void read()
{
printf("\nEnter the number of rows and columns for A matrix:");
scanf("%d%d",&m,&n);
printf("\nEnter the number of rows and columns for X matrix:");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("\nInvalid values for matrix multiplication\n");
}
else
{
printf("\nEnter the values for A matrix one by one\n");
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
printf("\nEnter the values for X matrix one by one\n");
for(i=1;i<=p;i++)
for(j=1;j<=q;j++)
scanf("%d",&x[i][j]);
mult();
}
}
void mult()
{
for(i=1;i<=m;i++)
for(j=1;j<=q;j++)
{
sum=0;
for(k=1;k<=p;k++)
{
sum=sum+a[i][k]*x[k][i];
}
c[i][j]=sum;
}
display();
}
void display()
{
printf("\nMATRIX A:\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("%d",a[i][j]);
printf("\t");
}
printf("\n");
}
printf("\n MATRIX X:\n");
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
printf("%d",x[i][j]);
printf("\t");
}
printf("\n");
}
printf("\n EVALUTION OF AX MATRIX \n");
for(i=1;i<=m;i++)
{
for(j=1;j<=q;j++)
{
printf("%d",c[i][j]);
printf("\t");
}
printf("\n");
}
}
Output

MATRIX MULTIPLICATION

Enter the number of rows and columns for A matrix: 2 2

Enter the number of rows and columns for X matrix: 2 2

Enter the values for A matrix one by one


1 1 1 1

Enter the values for X matrix one by one


6 6 6 6

MATRIX A:
1 1
1 1

MATRIX X:
6 6
6 6

EVALUTION OF AX MATRIX

12 12
12 12

Result

The above program is successfully executed and verified.


Write a C Program to generate n Fibonacci numbers using recursion.
Ex.No : 5 PRINTING FIBONACCI NUMBERS

Aim:

To generate a Fibonacci numbers.

Algorithm:

Step 1: Start the process.

Step 2: Get the value of n upto which the Fibonacci series of numbers have to be

displayed.

Step 3: If n<=0,print the message that shows n value must be greater than zero.

Step 4: If n>0,print n Fibonacci numbers.

Step 5: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
int fibonacci(int);
void main()
{
int n,i;
printf ("***FIBONACCI SERIES\n");
printf("Enter the number of fibonacci numbers to be printed:");
scanf("%d",&n);
if (n==0)
{
printf("Enter n value greater than zero\n");
}
for(i=0;i<n;i++)
{
printf("%d\n",fibonacci(i));
}
}
int fibonacci(int n)
{
if (n==0)
{
return 0;
}
else if(n==1)
{
return 1;
}
else
{
return(fibonacci(n-1)+fibonacci(n-2));
}
}
Output

***FIBONACCI SERIES***
Enter the number of fibonacci numbers to be printed:20
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181

Result

The above program is successfully executed and verified.


Implement binary search to find a particular name from a list.
Ex. No : 6 BINARY SEARCH

Aim:

To write a program to implement binary search to find the a particular name from a list.

Algorithm:

Step 1: Start the process.

Step 2: Declare the necessary variable get the total number of names to be in the list.

Step 3: Using for loop get the names.

Step 4: Arrange the names in ascending using strcmp and strcpy functions.

Step 5: Get the name which has to be searched in the list of names.

Step 6: Using while loop and strcmp function search required name and calculate the

position.

Step 7: Print whether the required naming the list, print the result with the search names

position or else print that the name has not been in the list.

Step 8: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
#include<string.h>
void main()
{
char name[50][15],dummy[15],sname[15];
int i,j,n,upp,low,mid,sb=1;
char choice;
printf("\n\t\t\tBINARY SEARCH");
printf("\n\t\t\t*************");
printf("\nEnter the number of names in the list:");
scanf("%d",&n);
printf("\n Enter the names one by one:\n");
for(i=0;i<n;i++)
scanf("%s[^\n]",name[i]);
printf("\n Enter the name to be search:\n");
scanf("%s[^\n]",sname);
printf("\nNames in the list:");
for(i=0;i<n;i++)
printf("\n%s",name[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(strcmp(name[i],name[j])<0)
{
strcpy(dummy,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],dummy);
}
printf("\nSorted name list:");
for(i=0;i<n;i++)
printf("\n%s",name[i]);
low=0;upp=n;
while(low<=upp)
{
mid=(low+upp)/2;
if(strcmp(sname,name[mid])==0)
{
sb=0;
printf("\n%s is found in position:%d\n",sname,mid);
break;
}
else if(strcmp(sname,name[mid])>0)
low=mid+1;
else if(strcmp(sname,name[mid])<0)
upp=mid-1;
}
if(sb==1)
printf("\n%s is not found in the list",sname);
}
Output

BINARY SEARCH
****************
Enter the number of names in the list:5

Enter the names one by one:


Rithanya
Sanmathi
Karthika
Anusha
Pavithra

Enter the name to be search:


Sanmathi

Names in the list:


Rithanya
Sanmathi
Karthika
Anusha
Pavithra

Sorted name list:


Anusha
Karthika
Pavithra
Rithanya
Sanmathi

Sanmathi is found in position:5

Result
The above program is successfully executed and verified.
Write a c program to count the number of vowels and consonants in a given line of test using

pointers.
Ex.No : 7 VOWELS AND CONSONANTS

Aim:

To write a program to count the number of vowels and consonants in a given line of text

using pointers.

Algorithm:

Step 1: Start the process.

Step 2: Declare the required variables and also a pointers variable.

Step 3: Get the line of text.

Step 4: Using while loop, check the input text.

Step 5: Using if statement, count the number of vowels and consonants in a given line of

text.

Step 6: Print the result.

Step 7: Stop the process.


Program

#include<stdio.h>
#include<ctype.h>
#include<curses.h>
int main()
{
char str[100];
char*ptr;
int cntV,cntC,punt,space,digit;
printf("\n\t\t VOWELS AND CONSONANTS");
printf("\n\t\t *********************");
printf("\n Enter a line of text:");
scanf("%[^\n]",str);
ptr=str;
cntV=cntC=0;
while(*ptr!='\0')
{

if(*ptr=='A'||*ptr=='E'||*ptr=='I'||*ptr=='O'||*ptr=='U'||*ptr=='a'||*ptr=='e'||*ptr=='i'||*ptr==
'o'||*ptr=='u')
cntV++;
else if(ispunct(*ptr))
punt++;
else if(isspace(*ptr))
space++;
else if(*ptr>='a'&&*ptr<='z'||(*ptr>='A'&&*ptr<='Z'))
cntC++;
else
digit++;
ptr++;
}
printf("\n Total number of VOWELS:%d,CONSONANTS:%d\n",cntV,cntC);
}
Output

VOWELS AND CONSONANTS


***************************
Enter a line of text:The quick brown fox jumps over the lazy dog

Total number of VOWELS:11,CONSONANTS:24

Result

The above program is successfully executed and verified.


Write a C Program to generate permutation of a given string using pointer.
Ex.No : 8 PERMUTATION OF A STRING

Aim:

To generate permutation of a given string using string pointers.

Algorithm:

Step 1: Start the process.

Step 2: Declare the require variable.

Step 3: Get the string for which the premutation home to be generation.

Step 4: Call permute() functions to perform permutation.

Step 5: In permute() function,call swap() and permute() function whenever needed.

Step 6: In swap() function the letters are swaped to generate the premutation.

Step 7: Display the generated permutation.

Step 8: Stop the process.


Program
#include<stdio.h>
#include<string.h>
void swap(char*x,char*y)
{
char temp;
temp=*x;
*x=*y;
*y=temp;
}
void permute(char*a,int i,int n)
{
int j;
if(i==n)
{
printf("%s\n",a);
}
else
{
for(j=i;j<=n;j++)
{
swap((a+i),(a+j));
permute(a,i+1,n);
swap((a+i),(a+j));
}
}
}
int main()
{
char a[20];
int n,count;
printf("\n\t\tPERMUTATION OF A STRING\n");
printf("\n\t\t****************************");
printf("\n\t\tEnter a string:\n");
scanf("%s",a);
n=strlen(a);
printf("\nThe length of the given string is%d\n",n);
printf("\n\nPermutations:\n");
permute(a,0,n-1);
return 0;
}
Output

PERMUTATION OF A STRING
***************************
Enter a string: ABCD

The length of the given string is 4

Permutations:

ABCD
ABDC
ACBD
ACDB
ADCB
ADBC
BACD
BADC
BCAD
BCDA
BDCA
BDAC
CBAD
CBDA
CABD
CADB
CDAB
CDBA
DBCA
DBAC
DCBA
DCAB
DACB
DABC

Result

The above program is successfully executed and verified.


The physical fitness criteria are listed here for the District Officer (Fire and Rescue)

District Officer  Men


(Fire and Rescue)  Age Limit– 21-32
 Minimum Height – 165 cms
 Minimum Weight – 50 kgs
 Minimum Chest (Full Inspiration) – 89 cms
 Minimum Chest (Normal) – 84 cms
 Minimum Chest Expansion – 5 cms
 Women
 Age Limit– 21-32
 Minimum Height – 155 cms

Write a program to check whether the person is eligible for the above given post
Ex.No : 9 PHYSICAL FITNESS CRITERIA

Aim:

To write a program to check whether the person is eligible for the given post.
Algorithm:

Step 1: Start the process.

Step 2: Declare the variables to get age, height, weight, chest details in Integer data type
and sex in character data type.

Step 3: Get the value from the user.

Step 4: Using nested if-else statement check whether the eligible for the given post.

Step 5: print the result

Step 6: Stop the process


Program

#include<stdio.h>
#include<curses.h>
#include<string.h>
void main()
{
int age,ht,wt,c1,c2,c3;
char sex;
char name[20];
printf("\t Physical fitness criteria for the post of district office(fire and rescue)\n");
printf("Enter name:");
fgets(name,20,stdin);
printf("\nEnter candidate sex(M/F):");
scanf("%c",&sex);
if(sex=='M')
{
printf("Enter age:");
scanf("%d",&age);
printf("Enter height:");
scanf("%d",&ht);
printf("Enter weight:");
scanf("%d",&wt);
printf("Enter chest (full Inspiration):");
scanf("%d",&c1);
printf("Enter chest (normal)):");
scanf("%d",&c2);
printf("Enter chest (expansion):");
scanf("%d",&c3);
if((age>=21)&&(age<=32)&&(ht>=165)&&(wt>=56)&&(c1>=89)&&(c2>=84)&&(c3>
=85))
{
printf("Eligible for the post of District Officer(fire and rescue)\n");
}
else
{
printf("Not eligible for the post of District Officer(fire and rescue)\n");
}
}
else
{
printf("Enter valid sex for the candidate\n");
}
}
Output

Physical fitness criteria for the post of district office(fire and rescue)

Enter name: RAJU

Enter candidate sex(M/F): M


Enter age: 25
Enter height: 175
Enter weight: 70
Enter chest (full Inspiration): 94
Enter chest (normal)): 90
Enter chest (expansion): 92
Eligible for the post of District Officer (fire and rescue)

Result

The above program is successfully executed and verified.


Write a program to print the Hallow Square Star pattern

*********
* *
* *
* *
* *
* *
*********
Ex.No : 10 HALLOW SQUARE STAR PATTERN

Aim:

To write a C program to print hallow square star pattern.

Algorithm:

Step 1: Start the process.

Step 2: Declare the necessary variables.

Step 3: Get the size of the square.

Step 4: Print the hallow square.

Step 5: Stop the process


Program

#include<stdio.h>
#include<curses.h>
int main()
{
int i,j,n;
printf("\n\t\t Hallow Square Star Pattern");
printf("\n\t\t **********************");
printf("\n\t\t Enter number of rows:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==1||i==n||j==1||j==n)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
Output

Hallow Square Star Pattern


**********************
Enter number of rows:6

******
* *
* *
* *
* *
******

Result

The above program is successfully executed and verified.


Write a program to print the student mark sheet assuming register number, names and

marks in five subjects using structure .


Ex.No : 11 STUDENT MARKSHEET

Aim:

To print the student mark sheet assuming register number, names and marks in five subjects

using structures.

Algorithm:

Step 1: Start the process.

Step 2: Declare the require variables and the structure variables.

Step 3: Get the student details such as name,register no,dob,month and year of passing.

Step 4: Get the total number of students whose details are to be enter.

Step 5: Using for loop get five subject marks.

Step 6: Using for loop print the student details and also calculate student total marks.

Step 7: Using if statement check whether mark is greater than 40 if mark is greater than

40 print the result as pass or else print the result as fail.

Step 8: Display the result in each subject and also total.

Step 9: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
#include<string.h>
struct student
{
char regno[20];
char name[20];
char dob[15];
int marks[5];
int total;
}stu[20];
main()
{
int i,j,n,sno;
char result[5];
char myp[50];
char sub[50][50]={"Tamil","English","Maths","ctheory","clab"};
printf("\n\n\tSTUDENTS MARKSHEET");
printf("\n\n\t******************");
printf("\n Enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter %d students details",i+1);
printf("\n Enter student name:");
scanf("%s",stu[i].name);
printf("\n Enter the student regno:");
scanf("%s",stu[i].regno);
printf("\n Enter the student DOB:");
scanf("%s",stu[i].dob);
printf("\nEnter the month and year of passing:");
scanf("%s[^/n]",myp);
printf("\nEnter the five subject marks:");
for(j=0;j<5;j++)
{
scanf("%d",&stu[i].marks[j]);
}
}
for(i=0;i<n;i++)
{
printf("\n\t\t VELLALAR COLLEGE FOR WOMEN(AUTONOMOUS),ERODE-12\n");
printf("\n\t\t\t I-B.SC Computer science(SF)'A'\n");
printf("\n\t\t NAME:%s\t\tDOB:%s\t",stu[i].name,stu[i].dob);
printf("\n\t\tREGNO:%s\t\tMONTH AND YEAR OF PASSING:%s",stu[i].regno,myp);
printf("\n\t\t____________________________________________________");
printf("\n\t\t s.no\t subject\t marks\t Result");
printf("\n\t\t\t__________________________________________________");
for(j=0;j<5;j++)
{
if (stu[i].marks[j]<40)
strcpy(result,"fail");
else
strcpy(result,"pass");
stu[i].total=stu[i].total+stu[i].marks[j];
printf("\n\t\t%d\t%s\t\t%d\t%s\t",j+1,sub[j],stu[i].marks[j],result);
}
printf("\n\t\t\t\tTOTAL:%d\n",stu[i].total);
}
}
Output

STUDENTS MARKSHEET
***********************
Enter the number of students:2
Enter 1 students details
Enter student name: ARTHI
Enter the student regno: 101
Enter the student DOB: 25/02/2000
Enter the month and year of passing: APR-2021
Enter the five subject marks: 75 65 85 90 80

Enter 2 students details


Enter student name: BHARATHI
Enter the student regno: 102
Enter the student DOB: 11/09/2000
Enter the month and year of passing: APR-2021
Enter the five subject marks: 92 83 80 75 70

VELLALAR COLLEGE FOR WOMEN(AUTONOMOUS),ERODE-12


I-B.SC Computer Science(SF)'A'
NAME:ARTHI DOB:25/02/2000
REGNO:101 MONTH AND YEAR OF PASSING:APR-2021
__________________________________________________
s.no subject marks Result
__________________________________________________
1 Tamil 75 pass
2 English 65 pass
3 Maths 85 pass
4 ctheory 90 pass
5 clab 80 pass

TOTAL:395
VELLALAR COLLEGE FOR WOMEN(AUTONOMOUS),ERODE-12

I-B.SC Computer Science(SF)'A'

NAME:BHARATHI DOB:11/09/2000

REGNO:102 MONTH AND YEAR OF PASSING:APR-2021


____________________________________________________
s.no subject marks Result
__________________________________________________
1 Tamil 92 pass
2 English 83 pass
3 Maths 80 pass
4 ctheory 75 pass
5 clab 70 pass

TOTAL :400

Result

The above program is successfully executed and verified.


Write a Program to find

i) complementary of nucleotides given DNA sequence

ii) Percentage of nucleotides ACGT in the given DNA sequence.


Ex.No : 12 COMPLEMENTARY SEQUENCE AND PERCENTAGE OF

NUCLEOTIDES IN A DNA

Aim:

To write a program to find complementary of nucleotides given DNA sequence and

percentage of nucleotides ACGT in the given DNA sequence.

Algorithm:

Step 1: Start the process.

Step 2: Declare the require variables.

Step 3: Enter the length of DNA sequence initially and then get the DNA sequence

which is combination of A,C,G,T.

Step 4: Using for loop and else if ladder check whether each character is A|C|T|G.

Step 5: If any of the character is A|G|T|C replace it with T|C|A|G also count the

occurence of each character.

Step 6: Calculate the percentage of each character using the count value.

Step 7: Display the complementary sequence and the percentage of occurrence.

Step 8: Stop the process.


Program

#include<stdio.h>
#include<curses.h>
void main()
{
int i,n;
printf("\n\t\t COMPLEMENTARY SEQUENCE AND PERCENTAGE OF
NUCLEOIDS IN A DNA \n");
printf("\n\n Enter the length of the sequence:\n");
scanf("%d",&n);
char seq[n],com[100]="";
int a=0,t=0,g=0,c=0;
float aper,tper,cper,gper;
printf("\n Enter sequence:");
scanf("%s",seq);
printf("\n The given sequence:%s",seq);
for(i=0;i<n;i++)
{
if(seq[i]=='A')
{
com[i]='T';
a=a+1;
}
else if (seq[i]=='T')
{
com[i]='A';
t=t+1;
}
else if (seq[i]=='G')
{
com[i]='C';
g=g+1;
}
else if(seq[i]=='C')
{
com[i]='G';
c=c+1;
}
}
printf("\n\n COMPLEMENTARY SEQUENCE IN A DNA:%s\n",com);
printf("\n PERCENTAGE OF NUCLEOTIDES IN A DNA");
aper=(float)a/n*100;
tper=(float)t/n*100;
cper=(float)c/n*100;
gper=(float)g/n*100;
printf("\n A:%5.2f \t T:%5.2f \t C:%5.2f \t G:%5.2f \n",aper,tper,cper,gper);
}
Output

COMPLEMENTARY SEQUENCE AND PERCENTAGE OF


NUCLEOIDS IN A DNA

Enter the length of the sequence:


10

Enter sequence:AATTCCGGAT

The given sequence:AATTCCGGAT

COMPLEMENTARY SEQUENCE IN A DNA:TTAAGGCCTA

PERCENTAGE OF NUCLEOTIDES IN A DNA


A:30.00 T:30.00 C:20.00 G:20.00

Result

The above program is successfully executed and verified.

You might also like