SlideShare a Scribd company logo
1 of 51
Array
08/23/151
08/23/152
08/23/153
08/23/154
08/23/155
08/23/156
08/23/157
08/23/158
08/23/159
08/23/1510
08/23/1511
08/23/1512
08/23/1513
Contd.
08/23/1514
•For example, the array marks can be initialized while declaring
using this statement.
int marks[5]={51,62,43,74,55};
•The elements of the array marks can be referred to as marks [0],
marks [1],marks [2], marks [3] and marks [4], respectively.
•The memory representation of the array marks is shown in Figure.
As each element is of the type int (that is, 2 bytes long), the array
marks occupies ten contiguous bytes in memory and these bytes are
reserved in the memory at the compile-time.
Problem
double percentage[50];
If this array percentage is stored in memory starting from
address 3000. then what will be the address of
percentage[20] element.
08/23/1515
Ans: 3000+20*8= 3160
What will be size of array?
Ans:400
08/23/1516
Example 1: Find the minimum
of a set of 10 numbers
#include <stdio.h>
main(){
int a[10], i, min;
printf(“Enter 10 numbers:”);
for (i=0; i<10; i++)
scanf (“%d”, &a[i]);
min = a[0];
for (i=1; i<10; i++){
if (a[i] < min)
min = a[i];
}
printf (“n Minimum is %d”, min);
}
08/23/1517
Alternate Version1 for last
problem
#include <stdio.h>
#define SIZE 10
main(){
int a[SIZE], i, min;
printf(“Enter 10 numbers:”);
for (i=0; i< SIZE; i++)
scanf (“%d”, &a[i]);
min = a[0];
for (i=1; i< SIZE; i++){
if (a[i] < min)
min = a[i];
}
printf (“n Minimum is %d”, min);
} 08/23/1518
Alternate Version2 for last
problem
#include <stdio.h>
main(){
int a[500], i, min;
printf(“Enter number of elements:”);
scanf(“%d”,&n);
printf(“Enter n numbers:”);
for (i=0; i< n; i++)
scanf (“%d”, &a[i]);
min = a[0];
for (i=1; i< n; i++){
if (a[i] < min)
min = a[i];
}
printf (“n Minimum is %d”, min);
}
08/23/1519
Things you can not do with
array
• You cannot use = to assign one array variable to another
E.g. a = b; is illegal where a and b are arrays.
• You cannot use == to directly compare array variables
e.g. if (a = = b) is illegal.
• You cannot use directly scanf or printf arrays
printf (“…….”, a); is illegal.
08/23/1520
How to copy the elements of
one array to another?
By copying individual elements
for (j=0; j<25; j++)
a[j] = b[j];
08/23/1521
How to read the elements of an
array?
• By reading them one element at a time
for (j=0; j<25; j++)
scanf (“%f”, &a[j]);
• The ampersand (&) is necessary.
08/23/1522
08/23/1523
Problem- linear search in one-D array
Write a program that asks the user to enter n integers of an
array and an integer x. The program must search if n is in the
array of n integers.
Following is the sample output
08/23/1524
void main() {
int array[100], search, c, n;  
printf("Enter the number of elements in arrayn"); scanf("%d",&n);  
printf("Enter %d integer(s)n", n);  
for (c = 0; c < n; c++)
scanf("%d", &array[c]);  
printf("Enter the number to searchn");
scanf("%d", &search);  
for (c = 0; c < n; c++) {
if (array[c] == search){ /* if required element found */
printf("%d is present at location %d.n", search, c+1);
break;
}
}
if (c == n)
printf("%d is not present in array.n", search);  
} 08/23/1525
Sort one-D array and find its
median
void main(){
int i,j,n,temp,arr[100];
printf(“Enter n:”);
for(i=0;i<n;i++)
scanf(“%d”,&arr[i]);
for(i=0; i<n-1; i++) {
for(j=i+1; j<n; j++) {
if(arr[i] > arr[j]) { // swap elements
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
if(n%2==0) // if there is an even number of elements, median will be mean of the two elements in the middle
printf(“median is=%d”,(x[n/2] + x[n/2 - 1]) / 2.0);
else //else return the element in the middle
printf(“median is=%d”,x[n/2]);
}
08/23/1527
08/23/1528
08/23/1529
Initialization of Two-
Dimensional Array
Like a single-dimensional array, a two-dimensional array can
also be declared and initialized at the same time.
To understand the concept of two-dimensional array
initialization, consider this statement. 
int a[3] [2]={
                     {101,51},
         {l02,67},
                     {l03,76} }
08/23/1530
Initialization of Two-
Dimensional Array
In last statement, an array of type int having three rows and two
columns is declared and initialized.
This type of initialization is generally used to increase the readability.
However, the array a can also be initialized using this statement.
  int a[] [2]={101,51,l02,67,l03,76};
In this statement, the first two elements are stored in the first row,
next two in the second row and so on.
Note that while initializing a two-dimensional array, mentioning the
row size is optional, however, the column size must be specified.
08/23/1531
08/23/1532
How to read the elements of a 2-D
array?
• By reading them one element at a time
for (i=0; i<nrow; i++)
for (j=0; j<ncol; j++)
scanf (“%f”, &a[i][j]);
• The ampersand (&) is necessary.
08/23/1533
08/23/1534
08/23/1535
08/23/1536
08/23/1537
•int a[] [2]={101,51,l02,67,l03,76};
•For example, the elements of array are referred to as a [0] [0], a [0] [1], a [1] [0],
a [1] [1], a [2] [0] and a [2] [1] respectively.
•Generally, two-dimensional arrays are represented with the help of a matrix.
•However, in actual implementation, two-dimensional arrays are always allocated
contiguous blocks of memory.
•Figure shows the matrix and memory representation of two-dimensional array a.
Problem
long double array[10][15];
If base address is 2000 then what will be the address of
Array[5][6] element;
08/23/1538
Ans: 2000+(5*15+6)*10=2810
C program to find average marks obtained by a
class of 30 students in a test.
08/23/1539
08/23/1540
Example: Matrix Addition
08/23/1541
Example: Matrix Addition
08/23/1542
Indenting C Programs 
Why Indentation is Important: Good style is about making
your program
1. Clear
2. Understandable and
3. Easily modifiable. 
Use proper comment in program for better readability.
There are so many Indenting Styles like Kernel style, K&R style
and ANSI Style.
We will follow ANSI Style(also known as Allman style).
08/23/1543
Rules of ANSI Style 
 This style puts the brace associated with a control statement(if,while,for, etc.) on the
next line, indented to the same level as the control statement.
 Statements within the braces are indented to the next level(indented by one tab).
 Following is the code segment without proper indentation
while (x == y) {
printf(“x and y are same”);
printf(“Next What to Do!”);
}
Same code segment in ANSI style would be
while (x == y)
{
printf(“x and y are same”);
printf(“Next What to Do!”);
}
08/23/1544
Some Examples of Bad vs Good coding
style
Code without proper indentation:
void main(){
int a=40000,b=20000;
if(a<b) printf(“Wow!”);
else printf(“Really!”);
}
Same code segment in ANSI style would be
void main()
{
int a=40000,b=20000;
if(a<b) // comparison of a and b
printf(“Wow!”);
else
printf(“Really!”);
}
}
08/23/1545
Some Examples of Bad vs Good coding
style
Code without proper indentation:
#include<stdio.h>
void main(){
int row,col;
for (row=1; row<=5; row++) {
for (col=1; col<=5; col++) {
if(row==1 || row==5 || col==1 || col==5)
printf("*");
else
printf(" ");
}
printf("n");
}
}
08/23/1546
Some Examples of Bad vs Good coding
style
Same code segment in ANSI style would be:
void main()
{
int row,col;
for (row=1; row<=5; row++) //outer Loop
{
for (col=1; col<=5; col++) //Inner Loop
{
if(row==1 || row==5 || col==1 || col==5)
printf("*");
else
printf(" ");
}
printf("n");
}
}
08/23/1547
O/P?
main()
{
int arr[]=(12,13,14,15,16};
printf(“n%d , %d”,sizeof(arr), sizeof(arr[0]));
}
O/p
08/23/1548
10,2
O/P?
main()
{
float a[]= { 12.4, 2.3, 4.5, 6.7};
printf(“n %d”, sizeof(a)/sizeof(a[0]));
}
O/p
08/23/1549
16/4=4
O/p?
main( )
{
int three[3][ ] = {
2, 4, 3,
6, 8, 2,
2, 3 ,1
} ;
printf ( "n%d", three[1][1] ) ;
}
08/23/1550
Syntax error
Homework
Multiply two matrices of orders m*n and n*p
respectively.
08/23/1551

More Related Content

What's hot

Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programmingSaranyaK68
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiSowmya Jyothi
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
Array & Exception Handling in C# (CSharp)
Array & Exception Handling in C# (CSharp)Array & Exception Handling in C# (CSharp)
Array & Exception Handling in C# (CSharp)Sohanur63
 
2 data types and operators in r
2 data types and operators in r2 data types and operators in r
2 data types and operators in rDr Nisha Arora
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointerNishant Munjal
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4Saranya saran
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Machine Learning in Agriculture Module 3: linear regression
Machine Learning in Agriculture Module 3: linear regressionMachine Learning in Agriculture Module 3: linear regression
Machine Learning in Agriculture Module 3: linear regressionPrasenjit Dey
 

What's hot (20)

Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++[ITP - Lecture 17] Strings in C/C++
[ITP - Lecture 17] Strings in C/C++
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Arrays
ArraysArrays
Arrays
 
Strings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothiStrings in c mrs.sowmya jyothi
Strings in c mrs.sowmya jyothi
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Program
ProgramProgram
Program
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
Pointers In C
Pointers In CPointers In C
Pointers In C
 
Array & Exception Handling in C# (CSharp)
Array & Exception Handling in C# (CSharp)Array & Exception Handling in C# (CSharp)
Array & Exception Handling in C# (CSharp)
 
2 data types and operators in r
2 data types and operators in r2 data types and operators in r
2 data types and operators in r
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
Matlab Tutorial
Matlab TutorialMatlab Tutorial
Matlab Tutorial
 
Imp_Points_Scala
Imp_Points_ScalaImp_Points_Scala
Imp_Points_Scala
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Ch8 Arrays
Ch8 ArraysCh8 Arrays
Ch8 Arrays
 
Machine Learning in Agriculture Module 3: linear regression
Machine Learning in Agriculture Module 3: linear regressionMachine Learning in Agriculture Module 3: linear regression
Machine Learning in Agriculture Module 3: linear regression
 
Pointers
PointersPointers
Pointers
 

Similar to 10 array

C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Break and continue in C
Break and continue in C Break and continue in C
Break and continue in C vishnupriyapm4
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
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
 
Java R20 - UNIT-3.docx
Java R20 - UNIT-3.docxJava R20 - UNIT-3.docx
Java R20 - UNIT-3.docxPamarthi Kumar
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Appili Vamsi Krishna
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
Break and Continue Statement in C Programming
Break and Continue Statement in C ProgrammingBreak and Continue Statement in C Programming
Break and Continue Statement in C ProgrammingDhana malar
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfajajkhan16
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Vivek Singh
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 

Similar to 10 array (20)

C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Break and continue in C
Break and continue in C Break and continue in C
Break and continue in C
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
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
 
Java R20 - UNIT-3.docx
Java R20 - UNIT-3.docxJava R20 - UNIT-3.docx
Java R20 - UNIT-3.docx
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
Unit 2
Unit 2Unit 2
Unit 2
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Arrays
ArraysArrays
Arrays
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Break and Continue Statement in C Programming
Break and Continue Statement in C ProgrammingBreak and Continue Statement in C Programming
Break and Continue Statement in C Programming
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 

More from Rohit Shrivastava (13)

1 introduction-to-computer
1 introduction-to-computer1 introduction-to-computer
1 introduction-to-computer
 
17 structure-and-union
17 structure-and-union17 structure-and-union
17 structure-and-union
 
16 dynamic-memory-allocation
16 dynamic-memory-allocation16 dynamic-memory-allocation
16 dynamic-memory-allocation
 
14 strings
14 strings14 strings
14 strings
 
11 functions
11 functions11 functions
11 functions
 
8 number-system
8 number-system8 number-system
8 number-system
 
7 decision-control
7 decision-control7 decision-control
7 decision-control
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
2 memory-and-io-devices
2 memory-and-io-devices2 memory-and-io-devices
2 memory-and-io-devices
 
4 evolution-of-programming-languages
4 evolution-of-programming-languages4 evolution-of-programming-languages
4 evolution-of-programming-languages
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 

Recently uploaded

Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...akbard9823
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Personfurqan222004
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsThierry TROUIN ☁
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Person
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
sasti delhi Call Girls in munirka 🔝 9953056974 🔝 escort Service-
sasti delhi Call Girls in munirka 🔝 9953056974 🔝 escort Service-sasti delhi Call Girls in munirka 🔝 9953056974 🔝 escort Service-
sasti delhi Call Girls in munirka 🔝 9953056974 🔝 escort Service-
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Call Girls Service Dwarka @9999965857 Delhi 🫦 No Advance VVIP 🍎 SERVICE
Call Girls Service Dwarka @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SERVICECall Girls Service Dwarka @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SERVICE
Call Girls Service Dwarka @9999965857 Delhi 🫦 No Advance VVIP 🍎 SERVICE
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
AlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with FlowsAlbaniaDreamin24 - How to easily use an API with Flows
AlbaniaDreamin24 - How to easily use an API with Flows
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 

10 array

  • 14. Contd. 08/23/1514 •For example, the array marks can be initialized while declaring using this statement. int marks[5]={51,62,43,74,55}; •The elements of the array marks can be referred to as marks [0], marks [1],marks [2], marks [3] and marks [4], respectively. •The memory representation of the array marks is shown in Figure. As each element is of the type int (that is, 2 bytes long), the array marks occupies ten contiguous bytes in memory and these bytes are reserved in the memory at the compile-time.
  • 15. Problem double percentage[50]; If this array percentage is stored in memory starting from address 3000. then what will be the address of percentage[20] element. 08/23/1515 Ans: 3000+20*8= 3160 What will be size of array? Ans:400
  • 17. Example 1: Find the minimum of a set of 10 numbers #include <stdio.h> main(){ int a[10], i, min; printf(“Enter 10 numbers:”); for (i=0; i<10; i++) scanf (“%d”, &a[i]); min = a[0]; for (i=1; i<10; i++){ if (a[i] < min) min = a[i]; } printf (“n Minimum is %d”, min); } 08/23/1517
  • 18. Alternate Version1 for last problem #include <stdio.h> #define SIZE 10 main(){ int a[SIZE], i, min; printf(“Enter 10 numbers:”); for (i=0; i< SIZE; i++) scanf (“%d”, &a[i]); min = a[0]; for (i=1; i< SIZE; i++){ if (a[i] < min) min = a[i]; } printf (“n Minimum is %d”, min); } 08/23/1518
  • 19. Alternate Version2 for last problem #include <stdio.h> main(){ int a[500], i, min; printf(“Enter number of elements:”); scanf(“%d”,&n); printf(“Enter n numbers:”); for (i=0; i< n; i++) scanf (“%d”, &a[i]); min = a[0]; for (i=1; i< n; i++){ if (a[i] < min) min = a[i]; } printf (“n Minimum is %d”, min); } 08/23/1519
  • 20. Things you can not do with array • You cannot use = to assign one array variable to another E.g. a = b; is illegal where a and b are arrays. • You cannot use == to directly compare array variables e.g. if (a = = b) is illegal. • You cannot use directly scanf or printf arrays printf (“…….”, a); is illegal. 08/23/1520
  • 21. How to copy the elements of one array to another? By copying individual elements for (j=0; j<25; j++) a[j] = b[j]; 08/23/1521
  • 22. How to read the elements of an array? • By reading them one element at a time for (j=0; j<25; j++) scanf (“%f”, &a[j]); • The ampersand (&) is necessary. 08/23/1522
  • 24. Problem- linear search in one-D array Write a program that asks the user to enter n integers of an array and an integer x. The program must search if n is in the array of n integers. Following is the sample output 08/23/1524
  • 25. void main() { int array[100], search, c, n;   printf("Enter the number of elements in arrayn"); scanf("%d",&n);   printf("Enter %d integer(s)n", n);   for (c = 0; c < n; c++) scanf("%d", &array[c]);   printf("Enter the number to searchn"); scanf("%d", &search);   for (c = 0; c < n; c++) { if (array[c] == search){ /* if required element found */ printf("%d is present at location %d.n", search, c+1); break; } } if (c == n) printf("%d is not present in array.n", search);   } 08/23/1525
  • 26. Sort one-D array and find its median void main(){ int i,j,n,temp,arr[100]; printf(“Enter n:”); for(i=0;i<n;i++) scanf(“%d”,&arr[i]); for(i=0; i<n-1; i++) { for(j=i+1; j<n; j++) { if(arr[i] > arr[j]) { // swap elements temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } if(n%2==0) // if there is an even number of elements, median will be mean of the two elements in the middle printf(“median is=%d”,(x[n/2] + x[n/2 - 1]) / 2.0); else //else return the element in the middle printf(“median is=%d”,x[n/2]); }
  • 30. Initialization of Two- Dimensional Array Like a single-dimensional array, a two-dimensional array can also be declared and initialized at the same time. To understand the concept of two-dimensional array initialization, consider this statement.  int a[3] [2]={                      {101,51},          {l02,67},                      {l03,76} } 08/23/1530
  • 31. Initialization of Two- Dimensional Array In last statement, an array of type int having three rows and two columns is declared and initialized. This type of initialization is generally used to increase the readability. However, the array a can also be initialized using this statement.   int a[] [2]={101,51,l02,67,l03,76}; In this statement, the first two elements are stored in the first row, next two in the second row and so on. Note that while initializing a two-dimensional array, mentioning the row size is optional, however, the column size must be specified. 08/23/1531
  • 33. How to read the elements of a 2-D array? • By reading them one element at a time for (i=0; i<nrow; i++) for (j=0; j<ncol; j++) scanf (“%f”, &a[i][j]); • The ampersand (&) is necessary. 08/23/1533
  • 37. 08/23/1537 •int a[] [2]={101,51,l02,67,l03,76}; •For example, the elements of array are referred to as a [0] [0], a [0] [1], a [1] [0], a [1] [1], a [2] [0] and a [2] [1] respectively. •Generally, two-dimensional arrays are represented with the help of a matrix. •However, in actual implementation, two-dimensional arrays are always allocated contiguous blocks of memory. •Figure shows the matrix and memory representation of two-dimensional array a.
  • 38. Problem long double array[10][15]; If base address is 2000 then what will be the address of Array[5][6] element; 08/23/1538 Ans: 2000+(5*15+6)*10=2810
  • 39. C program to find average marks obtained by a class of 30 students in a test. 08/23/1539
  • 43. Indenting C Programs  Why Indentation is Important: Good style is about making your program 1. Clear 2. Understandable and 3. Easily modifiable.  Use proper comment in program for better readability. There are so many Indenting Styles like Kernel style, K&R style and ANSI Style. We will follow ANSI Style(also known as Allman style). 08/23/1543
  • 44. Rules of ANSI Style   This style puts the brace associated with a control statement(if,while,for, etc.) on the next line, indented to the same level as the control statement.  Statements within the braces are indented to the next level(indented by one tab).  Following is the code segment without proper indentation while (x == y) { printf(“x and y are same”); printf(“Next What to Do!”); } Same code segment in ANSI style would be while (x == y) { printf(“x and y are same”); printf(“Next What to Do!”); } 08/23/1544
  • 45. Some Examples of Bad vs Good coding style Code without proper indentation: void main(){ int a=40000,b=20000; if(a<b) printf(“Wow!”); else printf(“Really!”); } Same code segment in ANSI style would be void main() { int a=40000,b=20000; if(a<b) // comparison of a and b printf(“Wow!”); else printf(“Really!”); } } 08/23/1545
  • 46. Some Examples of Bad vs Good coding style Code without proper indentation: #include<stdio.h> void main(){ int row,col; for (row=1; row<=5; row++) { for (col=1; col<=5; col++) { if(row==1 || row==5 || col==1 || col==5) printf("*"); else printf(" "); } printf("n"); } } 08/23/1546
  • 47. Some Examples of Bad vs Good coding style Same code segment in ANSI style would be: void main() { int row,col; for (row=1; row<=5; row++) //outer Loop { for (col=1; col<=5; col++) //Inner Loop { if(row==1 || row==5 || col==1 || col==5) printf("*"); else printf(" "); } printf("n"); } } 08/23/1547
  • 48. O/P? main() { int arr[]=(12,13,14,15,16}; printf(“n%d , %d”,sizeof(arr), sizeof(arr[0])); } O/p 08/23/1548 10,2
  • 49. O/P? main() { float a[]= { 12.4, 2.3, 4.5, 6.7}; printf(“n %d”, sizeof(a)/sizeof(a[0])); } O/p 08/23/1549 16/4=4
  • 50. O/p? main( ) { int three[3][ ] = { 2, 4, 3, 6, 8, 2, 2, 3 ,1 } ; printf ( "n%d", three[1][1] ) ; } 08/23/1550 Syntax error
  • 51. Homework Multiply two matrices of orders m*n and n*p respectively. 08/23/1551