SlideShare a Scribd company logo
1 of 57
Unit III
KIRTHIKA KM /AP/CSE
Array
 An Array is a collection of similar data items, that
are stored under a common name.
 Array might belonging to any of the data types
 Array size must be a constant value.
 Always, Contiguous(adjacent) memory locations
are used to store array elements in memory.
KIRTHIKA KM /AP/CSE
Uses of array
 Stores the elements of same data type.
 Used for maintaining multiple variable names
using a single name.
 Used for sorting elements.
 Matrix operations can be performed using arrays.
 Arrays are also used in CPU scheduling.
KIRTHIKA KM /AP/CSE
Types of arrays
 Types
 One-Dimensional array
 Two-Dimensional array
 Multi-Dimensional array
KIRTHIKA KM /AP/CSE
One-Dimensional array
 Array declaration:
 Syntax:
data_type array_name[size];
 Example: int x[3];
X[0]
X[1]
X[2]
x
KIRTHIKA KM /AP/CSE
Array initialization
 The initializer for an array is a comma-separated list of constant
expressions enclosed in braces ({ }).
 The initializer is preceded by an equal sign (=).
 It is not necessary to initialize all elements in an array. If an array
is partially initialized, elements that are not initialized receive
the value of the appropriate type.
 Array initialization can be made either :
 At compile time or
 At run time
KIRTHIKA KM /AP/CSE
At compile time
 Syntax:
data_type array_name[size]={variables};
Example: int x[3]={5,3,7};
5
3
7
X[0]
X[1]
X[2]
x
KIRTHIKA KM /AP/CSE
At Run time
 Array can also be initialized at the run time.
Example:
while(i<10)
{
if(i<5)
sum[i]=0;
else
sum[i]=sum[i]+i;
}
Example:
scanf(“%d%d”,&a[0],&a[1]);
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int x[2],i;
printf("nEnter the inputs:");
for(i=0;i<2;i++)
scanf("%d",&x[i]);
for(i=0;i<2;i++)
printf("nThe value in x[%d] is %d",i,x[i]);
getch();
}
KIRTHIKA KM /AP/CSE
Output
Enter the inputs:3
6
The value in x[0] is 3
The value in x[1] is 6
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char x[5]={'a','b','c','d','e'};
clrscr();
for(i=0;i<5;i++)
printf("nThe value in x[%d] is %c",i,x[i]);
getch();
}
KIRTHIKA KM /AP/CSE
Output
The value in x[0] is a
The value in x[1] is b
The value in x[2] is c
The value in x[3] is d
The value in x[4] is e
KIRTHIKA KM /AP/CSE
Two-Dimensional array
 Array declaration
 Syntax:
data_type array_name[row_size] [col_size];
 Example: int x[3][2];
X[0][0]
X[1][0]
X[2][0]
Col 0 Col 1
row 0
row 1
row 2
X[0][1]
X[1][1]
X[2][1]
KIRTHIKA KM /AP/CSE
2-D Array Initialization
 Syntax:
data_type array_name[row_size] [col_size];={variables};
 Example: int x[2][2]={1,50,2,75};
KIRTHIKA KM /AP/CSE
Example
 int x[2][2]={ {1,50},
{2,75}
};
(or)
 int x[ ][2]={ {1,50},
{2,75}
};
KIRTHIKA KM /AP/CSE
 The array elements will be stored in contiguous
memory locations, and it is illustrated below:
1 50
2 75
row 0
row 1
Col 0 Col 1
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int x[2][2]={ {1,50},
{2,75}
};
clrscr();
for(i=0;i<2;i++)
for(j=0;j<2;j++)
printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]);
getch();
}
KIRTHIKA KM /AP/CSE
Output
The value in x[0][0] is 1
The value in x[0][1] is 50
The value in x[1][0] is 2
The value in x[1][1] is 75
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int x[][2]={ {1,50},{2,75},{3,65}};
clrscr();
for(i=0;i<=2;i++)
for(j=0;j<2;j++)
printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]);
getch();
}
KIRTHIKA KM /AP/CSE
Output
The value in x[0][0] is 1
The value in x[0][1] is 50
The value in x[1][0] is 2
The value in x[1][1] is 75
The value in x[2][0] is 3
The value in x[2][1] is 65
KIRTHIKA KM /AP/CSE
Matrix Addition
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,r1,r2,c1,c2;
int a[5][5],b[5][5],c[5][5];
clrscr();
step1:
printf("n Enter the size of matrix A:");
scanf("%d%d",&r1,&c1);
printf("n Enter the size of matrix B: ");
scanf("%d%d",&r2,&c2);
if((c1==c2)&&(r1==r2))
goto step2;
else
goto step1;
KIRTHIKA KM /AP/CSE
step2:
printf("n Enter the elements of matrix A n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("n Enter the elements of matrix B n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("t%d",&b[i][j]);
}
}
KIRTHIKA KM /AP/CSE
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=0;
c[i][j]=c[i][j]+a[i][j]+b[i][j];
}
}
printf("n The resultant matrix after addition of A & B isn");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%dt",c[i][j]);
printf("n");
}
getch();
}
KIRTHIKA KM /AP/CSE
Output
Enter the size of matrix A: 2
2
Enter the size of matrix B: 2
2
Enter the elements of matrix A
2
2
2
2
Enter the elements of matrix B
3
3
3
3
The resultant matrix after addition of A&B is
5 5
5 5
KIRTHIKA KM /AP/CSE
Matrix Multiplication
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,r1,r2,c1,c2;
int a[5][5],b[5][5],c[5][5];
clrscr();
step1:
printf("n Enter the size of matrix A n");
scanf("%d%d",&r1,&c1);
printf("n Enter the size of matrix B n");
scanf("%d%d",&r2,&c2);
if(c1==r2)
goto step2;
else
goto step1;
KIRTHIKA KM /AP/CSE
step2:
printf("n Enter the elements of matrix A n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("n Enter the elements of matrix B n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("t%d",&b[i][j]);
}
}
KIRTHIKA KM /AP/CSE
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
printf("%dt",c[i][j]);
printf("n");
}
getch();
} KIRTHIKA KM /AP/CSE
Output
Enter the size of matrix A:2
2
Enter the size of matrix B:2
2
Enter the elements of matrix A
4
4
4
4
Enter the elements of matrix B
4
4
4
4
The resultant matrix is
32 32
32 32 KIRTHIKA KM /AP/CSE
Enter the size of matrix A:2
3
Enter the size of matrix B:3
2
Enter the elements of matrix A
1
2
3
4
5
6
Enter the elements of matrix B
2
4
6
8
2
4
The resultant matrix is
20 32
50 80
KIRTHIKA KM /AP/CSE
Passing array to Function
 An array can be passed as a parameter to a function by
specifying the array's name without an index.
 Here an array is transferred as parameter to a function.
void main() void fun(n,b[])
{ {
void fun(int,int); int x,b[5];
int a[5],n; …………..
…………… …………..
fun(n,a);
…………… }
}
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void add(int,int b[]);
void main()
{
int a[5],i,n;
clrscr();
printf("n Enter the Number: ");
scanf("%d",&n);
printf("n Enter the Values: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
add(n,a);
}
KIRTHIKA KM /AP/CSE
void add(int x,int b[])
{
int sum=0,i;
for(i=0;i<x;i++)
sum=sum+b[i];
printf("nThe sum is: %d",sum);
}
KIRTHIKA KM /AP/CSE
Output
Enter the Number: 5
Enter the Values: 1
2
3
4
5
The sum is: 15
KIRTHIKA KM /AP/CSE
Array of Characters
 In an array the characters are terminated by the null
(‘0’) character.
 Example: char a[]={a,b,c};
a b c 0
KIRTHIKA KM /AP/CSE
Example
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0;
char a[]="abcd";
clrscr();
while(a[i]!='0')
{
printf("t%c",a[i]);
i++;
}
}
KIRTHIKA KM /AP/CSE
Output
a b c d
KIRTHIKA KM /AP/CSE
Multi Dimensional Array
 Arrays can have more than one dimension, these arrays-of-
arrays are called multidimensional arrays.
 Here is the general form of a multidimensional array
declaration:
datatype array_name [size1][size2]….[size n]
datatype - type of the data.
array_name -name of the array.
size -size of the array.
KIRTHIKA KM /AP/CSE
 They are very similar to standard arrays with the
exception that they have multiple sets of square
brackets after the array identifier.
 A two dimensional array can be thought of as a grid of
rows and columns.
 A two-dimensional array is an example in this section,
although the techniques can be extended to three or
more dimensions.
 The simplest form of the multidimensional array is the
two-dimensional array.
KIRTHIKA KM /AP/CSE
Example:
int a[3][3][3];
Col 0 Col 1 Col 2
row 0
row 1
row 2
X[0][0]
X[1][0]
X[2][0]
X[0][1]
X[1][1]
X[2][1]
X[0][2]
X[1][2]
X[2][2]
KIRTHIKA KM /AP/CSE
String
 The string is actually a one-dimensional array of characters
which is terminated by a null character '0'.
 All the string handling functions are prototyped in: string.h
header file. So while using any string related function, don't
forget to include string.h.
 String constants have double quote marks around them.
 String constants can be assigned to a char array either with no
size specified, or the size can also be specified, but don't forget to
leave a space for the null character.
KIRTHIKA KM /AP/CSE
String Handling Functions
 Strings are often needed to be manipulated by the programmer
according to the need of a problem. Hence, C provides a variety of
string handling functions.
 String handling functions refers to a group of functions
implementing various operations on strings.
 Some of the operations performed by the string handling
functions includes:
 Length (number of characters in the string).
 Concatenation (adding two are more strings)
 Comparing two strings.
 Substring (Extract substring from a given string)
 Copy(copies one string over another)
KIRTHIKA KM /AP/CSE
 The various string handling functions supported by C are as
follows:
 strlen()
It is used to find the length of the string.
syntax:
strlen(string)
 strcpy()
It is used to copy one string to another.
syntax:
strcpy(string1,string2)
 strcat()
It is used to combine two strings.
syntax:
strcat(string1,string2)
KIRTHIKA KM /AP/CSE
 strcmp()
It is used to compare two strings.
syntax:
strcmp(string1,string2)
 Returns 0 if two strings are equal.
 Return value <0 if s1 is less than s2.
 Return value >0 if s1 is greater than s2.
 strrev()
It used to reverse a string.
syntax:
strrev(string)
 strlwr(), strupr()
It used to change the case of a string.
syntax:
strlwr(string)
strupr(string)
KIRTHIKA KM /AP/CSE
 strncpy()
It used to copy ‘n’ characters of one string to another.
 strstr()
It is used to determine the first occurrence of a given string
in another string.
 strncat()
It appends source string to destination string up to specified
length.
 strspn()
It is used to find up to what length two strings are identical.
KIRTHIKA KM /AP/CSE
 strncmp()
It is used to compare ‘n’ character of two strings.
 strcmpi()
It is used to compare two strings without regarding the case.
 strnicmp()
It is used to compare first ‘n’ characters of two strings without
regarding the case.
 strchr()
It is used to determine the first occurrence of a given character
in a string.
 strrchr()
It is used to determine the last occurrence of a given character
in a string.
KIRTHIKA KM /AP/CSE
Example 1
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[]="college";
int b;
clrscr();
b=strlen(a);
printf("nThe length of the string is %d",b);
getch();
}
Output:
The length of the string is 7
KIRTHIKA KM /AP/CSE
Example 2
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="IT";
char b[ ]="Dept";
clrscr();
strcpy(a,b);
printf("nThe string is %s",a);
getch();
}
Output:
The string is Dept
KIRTHIKA KM /AP/CSE
Example 3
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="IT";
char b[ ]="Dept";
clrscr();
strcat(a,b);
printf("nThe string is %s",a);
getch();
}
Output:
The string is ITDept
KIRTHIKA KM /AP/CSE
Example 4
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
char b[ ]="it";
int i;
clrscr();
i=strcmp(a,b);
if(i==0)
printf("nstrings are equal:%d",i);
else if(i<0)
printf("nstring1 is less than string2:%d",i);
KIRTHIKA KM /AP/CSE
else
printf("nstring1 is greater than string2:%d",i);
getch();
}
Output:
string1 is greater than string2:100
KIRTHIKA KM /AP/CSE
Example 5
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
clrscr();
printf("nThe string is :%s",a);
strupr(a);
printf("nThe string after conversion to uppercase :%s",a);
strlwr(a);
printf("nThe string after conversion to lowercase :%s",a);
getch();
}
KIRTHIKA KM /AP/CSE
Output
The string is : itdept
The string after conversion to uppercase :ITDEPT
The string after conversion to lowercase : itdept
KIRTHIKA KM /AP/CSE
Example 6
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="Dept";
clrscr();
printf("nThe string is %s",strrev(a));
getch();
}
Output:
The string is tpeD
KIRTHIKA KM /AP/CSE
Example 7
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[ ]="itdept";
char b[15];
int i=0;
clrscr();
strncpy(b,a,2);
b[2]='0';
printf("nThe string is :%s",b);
getch();
}
Output:
The string is :it KIRTHIKA KM /AP/CSE
String Palindrome
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int len,i,j;
char str[15];
clrscr();
printf("n Enter the string:");
scanf("%s",str);
len=strlen(str);
KIRTHIKA KM /AP/CSE
for(i=0,j=len-1;i<len/2;i++,j--)
{
if(str[i]!=str[j])
{
printf("n The String is not a palindrome");
getch();
exit(0);
}
}
printf("n The String is a palindrome");
getch();
}
Output:
Enter the string: abcba
The String is a palindrome
KIRTHIKA KM /AP/CSE
KIRTHIKA KM /AP/CSE

More Related Content

What's hot (19)

C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C Programming
C ProgrammingC Programming
C Programming
 
functions in C
functions in Cfunctions in C
functions in C
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Tut1
Tut1Tut1
Tut1
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
C++ language basic
C++ language basicC++ language basic
C++ language basic
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Cs211 module 1_2015
Cs211 module 1_2015Cs211 module 1_2015
Cs211 module 1_2015
 
Arrays
ArraysArrays
Arrays
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
What is c
What is cWhat is c
What is c
 
Tutorial on c language programming
Tutorial on c language programmingTutorial on c language programming
Tutorial on c language programming
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 

Similar to Unit 3 arrays and_string

VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxrohinitalekar1
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.pptAqeelAbbas94
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptxJawadTanvir
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Structured data type
Structured data typeStructured data type
Structured data typeOmkar Majukar
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptNamakkalPasanga
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 

Similar to Unit 3 arrays and_string (20)

VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
 
Lecture 15_Strings and Dynamic Memory Allocation.pptx
Lecture 15_Strings and  Dynamic Memory Allocation.pptxLecture 15_Strings and  Dynamic Memory Allocation.pptx
Lecture 15_Strings and Dynamic Memory Allocation.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Structured data type
Structured data typeStructured data type
Structured data type
 
Unit 2
Unit 2Unit 2
Unit 2
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
 
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT IIC PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
C PROGRAMMING BASICS- COMPUTER PROGRAMMING UNIT II
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 

Unit 3 arrays and_string

  • 2. Array  An Array is a collection of similar data items, that are stored under a common name.  Array might belonging to any of the data types  Array size must be a constant value.  Always, Contiguous(adjacent) memory locations are used to store array elements in memory. KIRTHIKA KM /AP/CSE
  • 3. Uses of array  Stores the elements of same data type.  Used for maintaining multiple variable names using a single name.  Used for sorting elements.  Matrix operations can be performed using arrays.  Arrays are also used in CPU scheduling. KIRTHIKA KM /AP/CSE
  • 4. Types of arrays  Types  One-Dimensional array  Two-Dimensional array  Multi-Dimensional array KIRTHIKA KM /AP/CSE
  • 5. One-Dimensional array  Array declaration:  Syntax: data_type array_name[size];  Example: int x[3]; X[0] X[1] X[2] x KIRTHIKA KM /AP/CSE
  • 6. Array initialization  The initializer for an array is a comma-separated list of constant expressions enclosed in braces ({ }).  The initializer is preceded by an equal sign (=).  It is not necessary to initialize all elements in an array. If an array is partially initialized, elements that are not initialized receive the value of the appropriate type.  Array initialization can be made either :  At compile time or  At run time KIRTHIKA KM /AP/CSE
  • 7. At compile time  Syntax: data_type array_name[size]={variables}; Example: int x[3]={5,3,7}; 5 3 7 X[0] X[1] X[2] x KIRTHIKA KM /AP/CSE
  • 8. At Run time  Array can also be initialized at the run time. Example: while(i<10) { if(i<5) sum[i]=0; else sum[i]=sum[i]+i; } Example: scanf(“%d%d”,&a[0],&a[1]); KIRTHIKA KM /AP/CSE
  • 9. Example #include<stdio.h> #include<conio.h> void main() { int x[2],i; printf("nEnter the inputs:"); for(i=0;i<2;i++) scanf("%d",&x[i]); for(i=0;i<2;i++) printf("nThe value in x[%d] is %d",i,x[i]); getch(); } KIRTHIKA KM /AP/CSE
  • 10. Output Enter the inputs:3 6 The value in x[0] is 3 The value in x[1] is 6 KIRTHIKA KM /AP/CSE
  • 11. Example #include<stdio.h> #include<conio.h> void main() { int i; char x[5]={'a','b','c','d','e'}; clrscr(); for(i=0;i<5;i++) printf("nThe value in x[%d] is %c",i,x[i]); getch(); } KIRTHIKA KM /AP/CSE
  • 12. Output The value in x[0] is a The value in x[1] is b The value in x[2] is c The value in x[3] is d The value in x[4] is e KIRTHIKA KM /AP/CSE
  • 13. Two-Dimensional array  Array declaration  Syntax: data_type array_name[row_size] [col_size];  Example: int x[3][2]; X[0][0] X[1][0] X[2][0] Col 0 Col 1 row 0 row 1 row 2 X[0][1] X[1][1] X[2][1] KIRTHIKA KM /AP/CSE
  • 14. 2-D Array Initialization  Syntax: data_type array_name[row_size] [col_size];={variables};  Example: int x[2][2]={1,50,2,75}; KIRTHIKA KM /AP/CSE
  • 15. Example  int x[2][2]={ {1,50}, {2,75} }; (or)  int x[ ][2]={ {1,50}, {2,75} }; KIRTHIKA KM /AP/CSE
  • 16.  The array elements will be stored in contiguous memory locations, and it is illustrated below: 1 50 2 75 row 0 row 1 Col 0 Col 1 KIRTHIKA KM /AP/CSE
  • 17. Example #include<stdio.h> #include<conio.h> void main() { int i,j; int x[2][2]={ {1,50}, {2,75} }; clrscr(); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]); getch(); } KIRTHIKA KM /AP/CSE
  • 18. Output The value in x[0][0] is 1 The value in x[0][1] is 50 The value in x[1][0] is 2 The value in x[1][1] is 75 KIRTHIKA KM /AP/CSE
  • 19. Example #include<stdio.h> #include<conio.h> void main() { int i,j; int x[][2]={ {1,50},{2,75},{3,65}}; clrscr(); for(i=0;i<=2;i++) for(j=0;j<2;j++) printf("nThe value in x[%d][%d] is %d",i,j,x[i][j]); getch(); } KIRTHIKA KM /AP/CSE
  • 20. Output The value in x[0][0] is 1 The value in x[0][1] is 50 The value in x[1][0] is 2 The value in x[1][1] is 75 The value in x[2][0] is 3 The value in x[2][1] is 65 KIRTHIKA KM /AP/CSE
  • 21. Matrix Addition #include<stdio.h> #include<conio.h> void main() { int i,j,k,r1,r2,c1,c2; int a[5][5],b[5][5],c[5][5]; clrscr(); step1: printf("n Enter the size of matrix A:"); scanf("%d%d",&r1,&c1); printf("n Enter the size of matrix B: "); scanf("%d%d",&r2,&c2); if((c1==c2)&&(r1==r2)) goto step2; else goto step1; KIRTHIKA KM /AP/CSE
  • 22. step2: printf("n Enter the elements of matrix A n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { scanf("%d",&a[i][j]); } } printf("n Enter the elements of matrix B n"); for(i=0;i<r2;i++) { for(j=0;j<c2;j++) { scanf("t%d",&b[i][j]); } } KIRTHIKA KM /AP/CSE
  • 23. for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { c[i][j]=0; c[i][j]=c[i][j]+a[i][j]+b[i][j]; } } printf("n The resultant matrix after addition of A & B isn"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) printf("%dt",c[i][j]); printf("n"); } getch(); } KIRTHIKA KM /AP/CSE
  • 24. Output Enter the size of matrix A: 2 2 Enter the size of matrix B: 2 2 Enter the elements of matrix A 2 2 2 2 Enter the elements of matrix B 3 3 3 3 The resultant matrix after addition of A&B is 5 5 5 5 KIRTHIKA KM /AP/CSE
  • 25. Matrix Multiplication #include<stdio.h> #include<conio.h> void main() { int i,j,k,r1,r2,c1,c2; int a[5][5],b[5][5],c[5][5]; clrscr(); step1: printf("n Enter the size of matrix A n"); scanf("%d%d",&r1,&c1); printf("n Enter the size of matrix B n"); scanf("%d%d",&r2,&c2); if(c1==r2) goto step2; else goto step1; KIRTHIKA KM /AP/CSE
  • 26. step2: printf("n Enter the elements of matrix A n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) { scanf("%d",&a[i][j]); } } printf("n Enter the elements of matrix B n"); for(i=0;i<r2;i++) { for(j=0;j<c2;j++) { scanf("t%d",&b[i][j]); } } KIRTHIKA KM /AP/CSE
  • 28. Output Enter the size of matrix A:2 2 Enter the size of matrix B:2 2 Enter the elements of matrix A 4 4 4 4 Enter the elements of matrix B 4 4 4 4 The resultant matrix is 32 32 32 32 KIRTHIKA KM /AP/CSE
  • 29. Enter the size of matrix A:2 3 Enter the size of matrix B:3 2 Enter the elements of matrix A 1 2 3 4 5 6 Enter the elements of matrix B 2 4 6 8 2 4 The resultant matrix is 20 32 50 80 KIRTHIKA KM /AP/CSE
  • 30. Passing array to Function  An array can be passed as a parameter to a function by specifying the array's name without an index.  Here an array is transferred as parameter to a function. void main() void fun(n,b[]) { { void fun(int,int); int x,b[5]; int a[5],n; ………….. …………… ………….. fun(n,a); …………… } } KIRTHIKA KM /AP/CSE
  • 31. Example #include<stdio.h> #include<conio.h> void add(int,int b[]); void main() { int a[5],i,n; clrscr(); printf("n Enter the Number: "); scanf("%d",&n); printf("n Enter the Values: "); for(i=0;i<n;i++) scanf("%d",&a[i]); add(n,a); } KIRTHIKA KM /AP/CSE
  • 32. void add(int x,int b[]) { int sum=0,i; for(i=0;i<x;i++) sum=sum+b[i]; printf("nThe sum is: %d",sum); } KIRTHIKA KM /AP/CSE
  • 33. Output Enter the Number: 5 Enter the Values: 1 2 3 4 5 The sum is: 15 KIRTHIKA KM /AP/CSE
  • 34. Array of Characters  In an array the characters are terminated by the null (‘0’) character.  Example: char a[]={a,b,c}; a b c 0 KIRTHIKA KM /AP/CSE
  • 35. Example #include<stdio.h> #include<conio.h> void main() { int i=0; char a[]="abcd"; clrscr(); while(a[i]!='0') { printf("t%c",a[i]); i++; } } KIRTHIKA KM /AP/CSE
  • 36. Output a b c d KIRTHIKA KM /AP/CSE
  • 37. Multi Dimensional Array  Arrays can have more than one dimension, these arrays-of- arrays are called multidimensional arrays.  Here is the general form of a multidimensional array declaration: datatype array_name [size1][size2]….[size n] datatype - type of the data. array_name -name of the array. size -size of the array. KIRTHIKA KM /AP/CSE
  • 38.  They are very similar to standard arrays with the exception that they have multiple sets of square brackets after the array identifier.  A two dimensional array can be thought of as a grid of rows and columns.  A two-dimensional array is an example in this section, although the techniques can be extended to three or more dimensions.  The simplest form of the multidimensional array is the two-dimensional array. KIRTHIKA KM /AP/CSE
  • 39. Example: int a[3][3][3]; Col 0 Col 1 Col 2 row 0 row 1 row 2 X[0][0] X[1][0] X[2][0] X[0][1] X[1][1] X[2][1] X[0][2] X[1][2] X[2][2] KIRTHIKA KM /AP/CSE
  • 40. String  The string is actually a one-dimensional array of characters which is terminated by a null character '0'.  All the string handling functions are prototyped in: string.h header file. So while using any string related function, don't forget to include string.h.  String constants have double quote marks around them.  String constants can be assigned to a char array either with no size specified, or the size can also be specified, but don't forget to leave a space for the null character. KIRTHIKA KM /AP/CSE
  • 41. String Handling Functions  Strings are often needed to be manipulated by the programmer according to the need of a problem. Hence, C provides a variety of string handling functions.  String handling functions refers to a group of functions implementing various operations on strings.  Some of the operations performed by the string handling functions includes:  Length (number of characters in the string).  Concatenation (adding two are more strings)  Comparing two strings.  Substring (Extract substring from a given string)  Copy(copies one string over another) KIRTHIKA KM /AP/CSE
  • 42.  The various string handling functions supported by C are as follows:  strlen() It is used to find the length of the string. syntax: strlen(string)  strcpy() It is used to copy one string to another. syntax: strcpy(string1,string2)  strcat() It is used to combine two strings. syntax: strcat(string1,string2) KIRTHIKA KM /AP/CSE
  • 43.  strcmp() It is used to compare two strings. syntax: strcmp(string1,string2)  Returns 0 if two strings are equal.  Return value <0 if s1 is less than s2.  Return value >0 if s1 is greater than s2.  strrev() It used to reverse a string. syntax: strrev(string)  strlwr(), strupr() It used to change the case of a string. syntax: strlwr(string) strupr(string) KIRTHIKA KM /AP/CSE
  • 44.  strncpy() It used to copy ‘n’ characters of one string to another.  strstr() It is used to determine the first occurrence of a given string in another string.  strncat() It appends source string to destination string up to specified length.  strspn() It is used to find up to what length two strings are identical. KIRTHIKA KM /AP/CSE
  • 45.  strncmp() It is used to compare ‘n’ character of two strings.  strcmpi() It is used to compare two strings without regarding the case.  strnicmp() It is used to compare first ‘n’ characters of two strings without regarding the case.  strchr() It is used to determine the first occurrence of a given character in a string.  strrchr() It is used to determine the last occurrence of a given character in a string. KIRTHIKA KM /AP/CSE
  • 46. Example 1 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[]="college"; int b; clrscr(); b=strlen(a); printf("nThe length of the string is %d",b); getch(); } Output: The length of the string is 7 KIRTHIKA KM /AP/CSE
  • 47. Example 2 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="IT"; char b[ ]="Dept"; clrscr(); strcpy(a,b); printf("nThe string is %s",a); getch(); } Output: The string is Dept KIRTHIKA KM /AP/CSE
  • 48. Example 3 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="IT"; char b[ ]="Dept"; clrscr(); strcat(a,b); printf("nThe string is %s",a); getch(); } Output: The string is ITDept KIRTHIKA KM /AP/CSE
  • 49. Example 4 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; char b[ ]="it"; int i; clrscr(); i=strcmp(a,b); if(i==0) printf("nstrings are equal:%d",i); else if(i<0) printf("nstring1 is less than string2:%d",i); KIRTHIKA KM /AP/CSE
  • 50. else printf("nstring1 is greater than string2:%d",i); getch(); } Output: string1 is greater than string2:100 KIRTHIKA KM /AP/CSE
  • 51. Example 5 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; clrscr(); printf("nThe string is :%s",a); strupr(a); printf("nThe string after conversion to uppercase :%s",a); strlwr(a); printf("nThe string after conversion to lowercase :%s",a); getch(); } KIRTHIKA KM /AP/CSE
  • 52. Output The string is : itdept The string after conversion to uppercase :ITDEPT The string after conversion to lowercase : itdept KIRTHIKA KM /AP/CSE
  • 53. Example 6 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="Dept"; clrscr(); printf("nThe string is %s",strrev(a)); getch(); } Output: The string is tpeD KIRTHIKA KM /AP/CSE
  • 54. Example 7 #include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[ ]="itdept"; char b[15]; int i=0; clrscr(); strncpy(b,a,2); b[2]='0'; printf("nThe string is :%s",b); getch(); } Output: The string is :it KIRTHIKA KM /AP/CSE
  • 55. String Palindrome #include<stdio.h> #include<conio.h> #include<string.h> void main() { int len,i,j; char str[15]; clrscr(); printf("n Enter the string:"); scanf("%s",str); len=strlen(str); KIRTHIKA KM /AP/CSE
  • 56. for(i=0,j=len-1;i<len/2;i++,j--) { if(str[i]!=str[j]) { printf("n The String is not a palindrome"); getch(); exit(0); } } printf("n The String is a palindrome"); getch(); } Output: Enter the string: abcba The String is a palindrome KIRTHIKA KM /AP/CSE