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

Homework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorHomework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorLê Đại-Nam
 
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 DiagramsCharlton 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 opportunitiesAlexander Lifanov
 
Script clases ide bd espacial
Script clases ide   bd espacialScript clases ide   bd espacial
Script clases ide bd espacialfulllcreeed
 
Sketching derivatives
Sketching derivativesSketching derivatives
Sketching derivativesssuserdb91c91
 
Understanding the nodejs event loop
Understanding the nodejs event loopUnderstanding the nodejs event loop
Understanding the nodejs event loopSaurabh Kumar
 
SPSF02 - Graphical Data Representation
SPSF02 - Graphical Data RepresentationSPSF02 - Graphical Data Representation
SPSF02 - Graphical Data RepresentationSyeilendra Pramuditya
 
SPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSPSF04 - Euler and Runge-Kutta Methods
SPSF04 - Euler and Runge-Kutta MethodsSyeilendra 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 languageAshwini Mathur
 
Postfix Evaluations using Stack
Postfix Evaluations using StackPostfix Evaluations using Stack
Postfix Evaluations using StackSoumen 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

Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming languageLincoln 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 RYanchang 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 212Mahmoud 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 4Randa 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 ManualLewisSimmonss
 
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++ codePVS-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 SpeedYung-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 RyuJITEgor Bogatov
 
Story of static code analyzer development
Story of static code analyzer developmentStory of static code analyzer development
Story of static code analyzer developmentAndrey Karpov
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applicationsConnor 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) .docxwellesleyterresa
 

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

Georg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi RamalingamGeorg scheutz - Charles babbage - Saraswathi Ramalingam
Georg scheutz - Charles babbage - Saraswathi RamalingamSaraswathiRamalingam
 
Dennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAMDennis ritchie - SARASWATHI RAMALINGAM
Dennis ritchie - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
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 ramalingamSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMPROGRAMMING USING C# .NET - SARASWATHI RAMALINGAM
PROGRAMMING USING C# .NET - SARASWATHI RAMALINGAMSaraswathiRamalingam
 
LAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMLAB PROGRAMS SARASWATHI RAMALINGAM
LAB PROGRAMS SARASWATHI RAMALINGAMSaraswathiRamalingam
 

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

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

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