SlideShare a Scribd company logo
1 of 24
LAB EXERCISE 6 - 10
R SARASWATHI
SRI AKILANDESWARI WOMENS COLLEGE
Ex: 6. To Compute GCD and
LCM String Manipulation.
#include <stdio.h>
int gcd(int x, int y); //function prototype
int main()
{
int num1, num2, hcf, lcm;
printf("Enter two integer Values:n");
scanf("%d %d", &num1, &num2);
hcf = gcd(num1, num2);
printf("GCD: %d", hcf);
printf("nLCM: %d", (num1 * num2) / hcf);
return 0;
}
//recursive function
int gcd(int x, int y)
{
if (y == 0) //recursion termination condition
{
return x;
}
else
{
return gcd(y, x % y); //calls itself
}
}
Output
Enter two integer Values:
5
10
GCD: 5
LCM: 10
Ex:7 Operations on string such
as length, concatenation,
reverse, counting, and copy of a
string to another.
String Manipulation
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{ char str1[20],str2[20];
int ch,i,j,length,count=0;
do { printf("tMENU");
printf("n------------------------------n");
printf("1:Find Length of String");
printf("n2:Find Reverse of String");
printf("n3:Concatenate Strings");
printf("n4:Copy String ");
printf("n5:Vowels Counting");
printf("n6:Exit");
printf("n------------------------------n");
printf("nEnter your choice: ");
scanf("%d",&ch); switch(ch)
{
case 1:
printf("Enter String: ");
scanf("%s",str1);
i=strlen(str1);
printf("Length of String : %dnn",i);
break;
String Manipulation
case 2:
printf("Enter String: ");
scanf("%s",str1);
length=strlen(str1);
for(i = length - 1; i >= 0; i--)
{
printf("%c", str1[i]);
}
printf(" : Reverse stringn");
break;
case 3:
printf("nEnter First String: ");
scanf("%s",str1);
printf("Enter Second string: ");
scanf("%s",str2);
strcat(str1,str2);
printf("String After Concatenation : %snn",str1);
break;
String Manipulation
case 4:
printf("Enter a String1: ");
scanf("%s",str1);
printf("Enter a String2: ");
scanf("%s",str2);
printf("nString Before
Copied:nString1="%s",String2="%s"n",str1,str2);
strcpy(str2,str1);
printf("-----------------------------------------------n");
printf(""We are copying string String1 to String2" n");
printf("-----------------------------------------------n");
printf("String After
Copied:nString1="%s",String2="%s"nn",str1,str2);
break;
case 5:
printf("nEnter a String:[without space]t");
scanf("%s", str1);
length = strlen(str1);
for(i = 0; i < length; i++)
{
if(str1[i] == 'a' || str1[i] == 'e' || str1[i] == 'i' || str1[i] == 'o' || str1[i]
== 'u' || str1[i] == 'A' || str1[i] == 'E' || str1[i] == 'I'
|| str1[i] == 'O' || str1[i] == 'U')
count++;
}
printf("Total Vowels:%d n",count);
break;
case 6:
exit(0);
break;
default:
printf("Invalid Input. Please Enter valid Input.nn ");
} }
while(ch!=6);}
Output
MENU
------------------------------
1:Find Length of String
2:Find Reverse of String
3:Concatenate Strings
4:Copy String
5:Vowels Counting
6:Exit
------------------------------
Enter your choice: 1
Enter String: Structure
Length of String : 9
MENU
------------------------------
1:Find Length of String
2:Find Reverse of String
3:Concatenate Strings
4:Copy String
5:Vowels Counting
6:Exit
------------------------------
Enter your choice: 2
Enter String: union
noinu : Reverse string
MENU
------------------------------
1:Find Length of String
2:Find Reverse of String
3:Concatenate Strings
4:Copy String
5:Vowels Counting
6:Exit
------------------------------
Enter your choice: 3
Enter First String: Pointer
Enter Second string: Adree ss
String After Concatenation : PointerAdress
MENU
------------------------------
1:Find Length of String
2:Find Reverse of String
3:Concatenate Strings
4:Copy String
5:Vowels Counting
6:Exit
------------------------------
Enter your choice: 5
Enter a String:[without space] Variables
Total Vowels:4
MENU
------------------------------
1:Find Length of String
2:Find Reverse of String
3:Concatenate Strings
4:Copy String
5:Vowels Counting
6:Exit
------------------------------
Enter your choice: 6
Ex:8 Matrix Addition,
Subtraction, Multiplication,
Transpose of n x m matrices.
Matrix Manipulation
#include<stdio.h>
void main()
{
int r1,r2,c1,c2,i,j,k;
int m1[15][15],m2[15][15],a[15][15],s[15][15],m[15][15],t[15][15];
printf("ntt MATRIX MANIPULATION ");
printf("ntt ******************** ");
printf("n Enter the no.of rows and columns for matrix 1: ");
printf("n rows:");
scanf("%d",&r1);
printf("n columns:");
scanf("%d",&c1);
printf("Enter the values of martix 1: n");
for(i=1;i<=r1;i++)
for(j=1;j<=c1;j++)
scanf("%d",&m1[i][j]);
printf("n Enter the rows and columns of matrix 2: ");
printf("n rows:");
scanf("%d",&r2);
printf("columns:");
scanf("%d",&c2);
Matrix Manipulation
printf("n Enter the values of matrix 2: n");
for(i=1;i<=r2;i++)
for(j=1;j<=c2;j++)
scanf("%d",&m2[i][j]);
printf("n MATRIX ADDITION ");
printf("n --------------- n");
if(r1==r2&&c1==c2)
{
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
a[i][j]=m1[i][j]+m2[i][j];
printf("t%d",a[i][j]);
}
printf("n");
}}
else
printf("n matrix addition is not possible");
printf("n MATRIX SUBTRACTION");
printf("n ------------------ n");
Matrix Manipulation
if(r1==r2&&c1==c2)
{ for(i=1;i<=r1;i++)
{ for(j=1;j<=c1;j++)
{
s[i][j]=m1[i][j]-m2[i][j];
printf("t%d",s[i][j]);
}
printf("n");
}}
else
printf("nmatrix subtraction is not possible");
printf("n MATRIX MULTIPLICATIONS");
printf("n ---------------------- n");
if(r2==c1)
{
for(i=1;i<=r1;i++)
{
printf("n");
for(j=1;j<=c2;j++)
{
m[i][j]=0;
for(k=1;k<=r2;k++)
m[i][j]=m[i][j]+(m1[i][k]*m2[k][j]);
}}}
Matrix Manipulation
else
printf("n multiplication is not possible");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c2;j++)
printf("t%d",m[i][j]);
printf("n");
}
printf("nTRANSPOSE OF MATRIXn");
printf("n ---------------------- n");
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
t[i][j]=m1[j][i];
}
for(i=1;i<=c1;i++)
{
for(j=1;j<=r1;j++)
printf("t %d",t[i][j]);
printf("n");
}
getch();
}
Output
MATRIX MANIPULATION
********************
Enter the no.of rows and columns for matrix 1:
rows:3
columns:3
Enter the values of martix 1:
2 4 6 8 10 12 14 16 18
Enter the rows and columns of matrix 2:
rows:3
columns:3
Enter the values of matrix 2:
3 6 9 12 15 18 21 24 27
MATRIX ADDITION
--------------------------
5 10 15
20 25 30
35 40 45
MATRIX SUBTRACTION
------------------------------
-1 -2 -3
-4 -5 -6
-7 -8 -9
MATRIX MULTIPLICATIONS
--------------------------------
180 216 252
396 486 576
612 756 900
TRANSPOSE OF MATRIX
2 8 14
4 10 16
6 12 18
Ex: 9. Inverse of a square
matrix.
#include<stdio.h>
int main(){
int a[3][3],i,j;
float determinant=0;
printf("Enter the 9 elements of matrix[Transpose of 3X3 Matrix]: ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("nThe matrix isn");
for(i=0;i<3;i++){
printf("n");
for(j=0;j<3;j++)
printf("%dt",a[i][j]);
}
for(i=0;i<3;i++)
determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2][(i+1)%3]));
printf("nInverse of matrix is: nn");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%.2ft",((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/
determinant);
printf("nInverse of matrix is: nn");
for(i=0;i<3;i++){
for(j=0;j<3;j++)
printf("%.2ft",((a[(i+1)%3][(j+1)%3]
* a[(i+2)%3][(j+2)%3]) -
(a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/
determinant);
printf("n");
}
return 0;
}
Output
Enter the 9 elements of matrix: 3
5
2
1
5
8
3
9
2
The matrix is
3 5 2
1 5 8
3 9 2
Inverse of matrix is:
0.70 -0.25 0.07
-0.09 -0.00 0.14
-0.34 0.25 -0.11
Ex: 10. Binary Search
#include <stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
printf("Enter number of elementsn");
scanf("%d", &n);
printf("Enter %d unique integersn", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter value to findn");
scanf("%d", &search);
first = 0;
last = n - 1;
middle = (first+last)/2;
while (first <= last) {
if (array[middle] < search)
first = middle + 1;
else if (array[middle] == search) {
printf("%d found at location
%d.n", search, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the
list.n", search);
return 0;
}
Output
Enter number of elements
5
Enter 5 unique integers
8
6
4
3
2
Enter value to find
4
found at location 3
Enter number of elements
5
Enter 5 integers
2
3
4
5
6
Enter value to find
8
Not found! 8 isn't present in the list

More Related Content

What's hot

Week 10 part 1 pe 6282 Block Diagrams
Week  10 part 1 pe 6282   Block DiagramsWeek  10 part 1 pe 6282   Block Diagrams
Week 10 part 1 pe 6282 Block Diagrams
Charlton Inao
 
CM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGECM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGE
A Jorge Garcia
 
Script clases ide bd espacial
Script clases ide   bd espacialScript clases ide   bd espacial
Script clases ide bd espacial
fulllcreeed
 
5.4 Slope Intercept Form Part B
5.4 Slope Intercept Form Part B5.4 Slope Intercept Form Part B
5.4 Slope Intercept Form Part B
vmonacelli
 
Descriptive analytics in r programming language
Descriptive analytics in r programming languageDescriptive analytics in r programming language
Descriptive analytics in r programming language
Ashwini Mathur
 

What's hot (20)

Homework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorHomework 1 of Optical Semiconductor
Homework 1 of Optical Semiconductor
 
Matlab file
Matlab file Matlab file
Matlab file
 
Week 10 part 1 pe 6282 Block Diagrams
Week  10 part 1 pe 6282   Block DiagramsWeek  10 part 1 pe 6282   Block Diagrams
Week 10 part 1 pe 6282 Block Diagrams
 
CM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGECM1.4 Algorithms, python and SAGE
CM1.4 Algorithms, python and SAGE
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunities
 
Script clases ide bd espacial
Script clases ide   bd espacialScript clases ide   bd espacial
Script clases ide bd espacial
 
Sketching derivatives
Sketching derivativesSketching derivatives
Sketching derivatives
 
Snake.c
Snake.cSnake.c
Snake.c
 
Graph Algebra
Graph AlgebraGraph Algebra
Graph Algebra
 
Understanding the nodejs event loop
Understanding the nodejs event loopUnderstanding the nodejs event loop
Understanding the nodejs event loop
 
SPSF03 - Numerical Integrations
SPSF03 - Numerical IntegrationsSPSF03 - Numerical Integrations
SPSF03 - Numerical Integrations
 
SPSF02 - Graphical Data Representation
SPSF02 - Graphical Data RepresentationSPSF02 - Graphical Data Representation
SPSF02 - Graphical Data Representation
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
Lecture 2 f17
Lecture 2 f17Lecture 2 f17
Lecture 2 f17
 
MLE Example
MLE ExampleMLE Example
MLE Example
 
SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta Methods
 
5.4 Slope Intercept Form Part B
5.4 Slope Intercept Form Part B5.4 Slope Intercept Form Part B
5.4 Slope Intercept Form Part B
 
Descriptive analytics in r programming language
Descriptive analytics in r programming languageDescriptive analytics in r programming language
Descriptive analytics in r programming language
 
Postfix Evaluations using Stack
Postfix Evaluations using StackPostfix Evaluations using Stack
Postfix Evaluations using Stack
 
Save all the modules
Save all the modulesSave all the modules
Save all the modules
 

Similar to C PROGRAMS - SARASWATHI RAMALINGAM

Arna Friend Controls II Final
Arna Friend Controls II FinalArna Friend Controls II Final
Arna Friend Controls II Final
Arna Friend
 
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docxHW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
wellesleyterresa
 

Similar to C PROGRAMS - SARASWATHI RAMALINGAM (20)

2 d matrices
2 d matrices2 d matrices
2 d matrices
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Time Series Analysis and Mining with R
Time Series Analysis and Mining with RTime Series Analysis and Mining with R
Time Series Analysis and Mining with R
 
The Ring programming language version 1.10 book - Part 127 of 212
The Ring programming language version 1.10 book - Part 127 of 212The Ring programming language version 1.10 book - Part 127 of 212
The Ring programming language version 1.10 book - Part 127 of 212
 
Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4Introduction to matlab lecture 3 of 4
Introduction to matlab lecture 3 of 4
 
Econometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualEconometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions Manual
 
A scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ codeA scrupulous code review - 15 bugs in C++ code
A scrupulous code review - 15 bugs in C++ code
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
Arna Friend Controls II Final
Arna Friend Controls II FinalArna Friend Controls II Final
Arna Friend Controls II Final
 
How to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJITHow to add an optimization for C# to RyuJIT
How to add an optimization for C# to RyuJIT
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
 
Vcs16
Vcs16Vcs16
Vcs16
 
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docxHW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
 

More from SaraswathiRamalingam

More from SaraswathiRamalingam (20)

MACINTOSH
MACINTOSHMACINTOSH
MACINTOSH
 
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
 
XML - SAX
XML - SAXXML - SAX
XML - SAX
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
X FILES
X FILESX FILES
X FILES
 
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML SCHEMAS
 
XML
XMLXML
XML
 
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
 
Georg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi RamalingamGeorg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi Ramalingam
 
Dennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAMDennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAM
 
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingamArithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
Arithmetic expression INFIX TO POSTFIX CONVERTION saraswathi ramalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
 

Recently uploaded

Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptxREPRODUCTIVE TOXICITY  STUDIE OF MALE AND FEMALEpptx
REPRODUCTIVE TOXICITY STUDIE OF MALE AND FEMALEpptx
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...Navigating the Misinformation Minefield: The Role of Higher Education in the ...
Navigating the Misinformation Minefield: The Role of Higher Education in the ...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 

C PROGRAMS - SARASWATHI RAMALINGAM

  • 1. LAB EXERCISE 6 - 10 R SARASWATHI SRI AKILANDESWARI WOMENS COLLEGE
  • 2. Ex: 6. To Compute GCD and LCM String Manipulation. #include <stdio.h> int gcd(int x, int y); //function prototype int main() { int num1, num2, hcf, lcm; printf("Enter two integer Values:n"); scanf("%d %d", &num1, &num2); hcf = gcd(num1, num2); printf("GCD: %d", hcf); printf("nLCM: %d", (num1 * num2) / hcf); return 0; } //recursive function int gcd(int x, int y) { if (y == 0) //recursion termination condition { return x; } else { return gcd(y, x % y); //calls itself } }
  • 3. Output Enter two integer Values: 5 10 GCD: 5 LCM: 10
  • 4. Ex:7 Operations on string such as length, concatenation, reverse, counting, and copy of a string to another.
  • 5. String Manipulation #include<stdio.h> #include<string.h> #include<stdlib.h> void main() { char str1[20],str2[20]; int ch,i,j,length,count=0; do { printf("tMENU"); printf("n------------------------------n"); printf("1:Find Length of String"); printf("n2:Find Reverse of String"); printf("n3:Concatenate Strings"); printf("n4:Copy String "); printf("n5:Vowels Counting"); printf("n6:Exit"); printf("n------------------------------n"); printf("nEnter your choice: "); scanf("%d",&ch); switch(ch) { case 1: printf("Enter String: "); scanf("%s",str1); i=strlen(str1); printf("Length of String : %dnn",i); break;
  • 6. String Manipulation case 2: printf("Enter String: "); scanf("%s",str1); length=strlen(str1); for(i = length - 1; i >= 0; i--) { printf("%c", str1[i]); } printf(" : Reverse stringn"); break; case 3: printf("nEnter First String: "); scanf("%s",str1); printf("Enter Second string: "); scanf("%s",str2); strcat(str1,str2); printf("String After Concatenation : %snn",str1); break;
  • 7. String Manipulation case 4: printf("Enter a String1: "); scanf("%s",str1); printf("Enter a String2: "); scanf("%s",str2); printf("nString Before Copied:nString1="%s",String2="%s"n",str1,str2); strcpy(str2,str1); printf("-----------------------------------------------n"); printf(""We are copying string String1 to String2" n"); printf("-----------------------------------------------n"); printf("String After Copied:nString1="%s",String2="%s"nn",str1,str2); break;
  • 8. case 5: printf("nEnter a String:[without space]t"); scanf("%s", str1); length = strlen(str1); for(i = 0; i < length; i++) { if(str1[i] == 'a' || str1[i] == 'e' || str1[i] == 'i' || str1[i] == 'o' || str1[i] == 'u' || str1[i] == 'A' || str1[i] == 'E' || str1[i] == 'I' || str1[i] == 'O' || str1[i] == 'U') count++; } printf("Total Vowels:%d n",count); break; case 6: exit(0); break; default: printf("Invalid Input. Please Enter valid Input.nn "); } } while(ch!=6);}
  • 9. Output MENU ------------------------------ 1:Find Length of String 2:Find Reverse of String 3:Concatenate Strings 4:Copy String 5:Vowels Counting 6:Exit ------------------------------ Enter your choice: 1 Enter String: Structure Length of String : 9
  • 10. MENU ------------------------------ 1:Find Length of String 2:Find Reverse of String 3:Concatenate Strings 4:Copy String 5:Vowels Counting 6:Exit ------------------------------ Enter your choice: 2 Enter String: union noinu : Reverse string MENU ------------------------------ 1:Find Length of String 2:Find Reverse of String 3:Concatenate Strings 4:Copy String 5:Vowels Counting 6:Exit ------------------------------ Enter your choice: 3 Enter First String: Pointer Enter Second string: Adree ss String After Concatenation : PointerAdress
  • 11. MENU ------------------------------ 1:Find Length of String 2:Find Reverse of String 3:Concatenate Strings 4:Copy String 5:Vowels Counting 6:Exit ------------------------------ Enter your choice: 5 Enter a String:[without space] Variables Total Vowels:4 MENU ------------------------------ 1:Find Length of String 2:Find Reverse of String 3:Concatenate Strings 4:Copy String 5:Vowels Counting 6:Exit ------------------------------ Enter your choice: 6
  • 12. Ex:8 Matrix Addition, Subtraction, Multiplication, Transpose of n x m matrices.
  • 13. Matrix Manipulation #include<stdio.h> void main() { int r1,r2,c1,c2,i,j,k; int m1[15][15],m2[15][15],a[15][15],s[15][15],m[15][15],t[15][15]; printf("ntt MATRIX MANIPULATION "); printf("ntt ******************** "); printf("n Enter the no.of rows and columns for matrix 1: "); printf("n rows:"); scanf("%d",&r1); printf("n columns:"); scanf("%d",&c1); printf("Enter the values of martix 1: n"); for(i=1;i<=r1;i++) for(j=1;j<=c1;j++) scanf("%d",&m1[i][j]); printf("n Enter the rows and columns of matrix 2: "); printf("n rows:"); scanf("%d",&r2); printf("columns:"); scanf("%d",&c2);
  • 14. Matrix Manipulation printf("n Enter the values of matrix 2: n"); for(i=1;i<=r2;i++) for(j=1;j<=c2;j++) scanf("%d",&m2[i][j]); printf("n MATRIX ADDITION "); printf("n --------------- n"); if(r1==r2&&c1==c2) { for(i=1;i<=r1;i++) { for(j=1;j<=c1;j++) { a[i][j]=m1[i][j]+m2[i][j]; printf("t%d",a[i][j]); } printf("n"); }} else printf("n matrix addition is not possible"); printf("n MATRIX SUBTRACTION"); printf("n ------------------ n");
  • 15. Matrix Manipulation if(r1==r2&&c1==c2) { for(i=1;i<=r1;i++) { for(j=1;j<=c1;j++) { s[i][j]=m1[i][j]-m2[i][j]; printf("t%d",s[i][j]); } printf("n"); }} else printf("nmatrix subtraction is not possible"); printf("n MATRIX MULTIPLICATIONS"); printf("n ---------------------- n"); if(r2==c1) { for(i=1;i<=r1;i++) { printf("n"); for(j=1;j<=c2;j++) { m[i][j]=0; for(k=1;k<=r2;k++) m[i][j]=m[i][j]+(m1[i][k]*m2[k][j]); }}}
  • 16. Matrix Manipulation else printf("n multiplication is not possible"); for(i=1;i<=r1;i++) { for(j=1;j<=c2;j++) printf("t%d",m[i][j]); printf("n"); } printf("nTRANSPOSE OF MATRIXn"); printf("n ---------------------- n"); for(i=1;i<=r1;i++) { for(j=1;j<=c1;j++) t[i][j]=m1[j][i]; } for(i=1;i<=c1;i++) { for(j=1;j<=r1;j++) printf("t %d",t[i][j]); printf("n"); } getch(); }
  • 17. Output MATRIX MANIPULATION ******************** Enter the no.of rows and columns for matrix 1: rows:3 columns:3 Enter the values of martix 1: 2 4 6 8 10 12 14 16 18 Enter the rows and columns of matrix 2: rows:3 columns:3 Enter the values of matrix 2: 3 6 9 12 15 18 21 24 27
  • 18. MATRIX ADDITION -------------------------- 5 10 15 20 25 30 35 40 45 MATRIX SUBTRACTION ------------------------------ -1 -2 -3 -4 -5 -6 -7 -8 -9 MATRIX MULTIPLICATIONS -------------------------------- 180 216 252 396 486 576 612 756 900 TRANSPOSE OF MATRIX 2 8 14 4 10 16 6 12 18
  • 19. Ex: 9. Inverse of a square matrix. #include<stdio.h> int main(){ int a[3][3],i,j; float determinant=0; printf("Enter the 9 elements of matrix[Transpose of 3X3 Matrix]: "); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%d",&a[i][j]); printf("nThe matrix isn"); for(i=0;i<3;i++){ printf("n"); for(j=0;j<3;j++) printf("%dt",a[i][j]); } for(i=0;i<3;i++) determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2][(i+1)%3])); printf("nInverse of matrix is: nn"); for(i=0;i<3;i++){ for(j=0;j<3;j++) printf("%.2ft",((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/ determinant);
  • 20. printf("nInverse of matrix is: nn"); for(i=0;i<3;i++){ for(j=0;j<3;j++) printf("%.2ft",((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/ determinant); printf("n"); } return 0; }
  • 21. Output Enter the 9 elements of matrix: 3 5 2 1 5 8 3 9 2 The matrix is 3 5 2 1 5 8 3 9 2 Inverse of matrix is: 0.70 -0.25 0.07 -0.09 -0.00 0.14 -0.34 0.25 -0.11
  • 22. Ex: 10. Binary Search #include <stdio.h> int main() { int c, first, last, middle, n, search, array[100]; printf("Enter number of elementsn"); scanf("%d", &n); printf("Enter %d unique integersn", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("Enter value to findn"); scanf("%d", &search); first = 0; last = n - 1; middle = (first+last)/2; while (first <= last) {
  • 23. if (array[middle] < search) first = middle + 1; else if (array[middle] == search) { printf("%d found at location %d.n", search, middle+1); break; } else last = middle - 1; middle = (first + last)/2; } if (first > last) printf("Not found! %d isn't present in the list.n", search); return 0; }
  • 24. Output Enter number of elements 5 Enter 5 unique integers 8 6 4 3 2 Enter value to find 4 found at location 3 Enter number of elements 5 Enter 5 integers 2 3 4 5 6 Enter value to find 8 Not found! 8 isn't present in the list