SlideShare a Scribd company logo
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

Homework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorHomework 1 of Optical Semiconductor
Homework 1 of Optical Semiconductor
Lê Đại-Nam
 
Matlab file
Matlab file Matlab file
Matlab file
rampal singh
 
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 SAGEA Jorge Garcia
 
AST: threats and opportunities
AST: threats and opportunitiesAST: threats and opportunities
AST: threats and opportunities
Alexander Lifanov
 
Script clases ide bd espacial
Script clases ide   bd espacialScript clases ide   bd espacial
Script clases ide bd espacial
fulllcreeed
 
Sketching derivatives
Sketching derivativesSketching derivatives
Sketching derivatives
ssuserdb91c91
 
Snake.c
Snake.cSnake.c
Snake.c
Vijay Singh
 
Graph Algebra
Graph AlgebraGraph Algebra
Graph Algebra
Roi Lipman
 
Understanding the nodejs event loop
Understanding the nodejs event loopUnderstanding the nodejs event loop
Understanding the nodejs event loop
Saurabh Kumar
 
SPSF03 - Numerical Integrations
SPSF03 - Numerical IntegrationsSPSF03 - Numerical Integrations
SPSF03 - Numerical Integrations
Syeilendra Pramuditya
 
SPSF02 - Graphical Data Representation
SPSF02 - Graphical Data RepresentationSPSF02 - Graphical Data Representation
SPSF02 - Graphical Data Representation
Syeilendra Pramuditya
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
Lakshmi Sarvani Videla
 
Lecture 2 f17
Lecture 2 f17Lecture 2 f17
Lecture 2 f17
Eric Cochran
 
SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta Methods
Syeilendra Pramuditya
 
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 Bvmonacelli
 
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
 
Postfix Evaluations using Stack
Postfix Evaluations using StackPostfix Evaluations using Stack
Postfix Evaluations using Stack
Soumen Santra
 

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

2 d matrices
2 d matrices2 d matrices
2 d matrices
Himanshu Arora
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
SumitSingh813090
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
C++ Homework Help
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
Lincoln Hannah
 
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
Yanchang Zhao
 
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
Mahmoud Samir Fayed
 
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
Randa Elanwar
 
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
LewisSimmonss
 
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
PVS-Studio LLC
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
Osama Al-Mohaia
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
Yung-Yu Chen
 
Arna Friend Controls II Final
Arna Friend Controls II FinalArna Friend Controls II Final
Arna Friend Controls II FinalArna Friend
 
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
Egor Bogatov
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer development
Andrey Karpov
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
Connor McDonald
 
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

MACINTOSH
MACINTOSHMACINTOSH
XSL - XML STYLE SHEET
XSL - XML STYLE SHEETXSL - XML STYLE SHEET
XSL - XML STYLE SHEET
SaraswathiRamalingam
 
XML - SAX
XML - SAXXML - SAX
DOM-XML
DOM-XMLDOM-XML
X FILES
X FILESX FILES
XML SCHEMAS
XML SCHEMASXML SCHEMAS
XML
XMLXML
XML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITIONXML DTD DOCUMENT TYPE DEFINITION
XML DTD DOCUMENT TYPE DEFINITION
SaraswathiRamalingam
 
Georg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi RamalingamGeorg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi Ramalingam
SaraswathiRamalingam
 
Dennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAMDennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
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
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAM
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

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.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