SlideShare a Scribd company logo
1 of 27
PREPARED BY- PRADEEP DWIVEDI(persuing  B.TECH-IT) 	from HINDUSTAN COLLEGE OF SCIENCE AND 			  TECHNOLOGY(MATHURA) 	MOB-+919027843806 	E-MAIL-pradeep.it74@gmail.com	 C-PROGRAMMING SLIDE-5 Wednesday, September 01, 2010 1 PRADEEP DWIVWDI
 ARRAY TOPIC Wednesday, September 01, 2010 2 PRADEEP DWIVWDI
ARRAY We use fundamental data type, namely char, int, float, double. Variable of these types can store only one value at a time. In many application we need to store more than one value of data in a single variable that time we use array. ARRAY:- is a fixed size sequenced collection of same data type. In other words, an ARRAY is a special variable that can hold the place for more than one values of same data type at adjacent places.  Wednesday, September 01, 2010 3 PRADEEP DWIVWDI
EXAMPLE OF ARRAY List of name. List of number. List of students mark. etc. Wednesday, September 01, 2010 4 PRADEEP DWIVWDI
DECLARATION AND MEMORY REPRESENTATION OF AN ARRAY                int a[10]; 0 	    1    2     3    4   5    6    7    8    9	 Data type Declaration of an array                                               variable dimension Memory representation Index /subscripted number Wednesday, September 01, 2010 5 PRADEEP DWIVWDI
TYPES OF ARRAY We have following types of array- One dimensional array. Two dimensional array. Multidimensional array. Wednesday, September 01, 2010 6 PRADEEP DWIVWDI
ONE DIMENSIONAL ARRAY A list of item can given one variable name using only one subscript  and such a variable called single subscripted variable or a one dimensional array. For, eg- if we want to represent a set of five numbers says (10,20,30,40,50), by an array variable num, then we declare the variable num as follows- 		int num[5]; Wednesday, September 01, 2010 7 PRADEEP DWIVWDI
ONE DIMENSIONAL ARRAY The computer reserves five storage in memory-                   num[0] 			num[1] 			num[2] 			num[3] 			num[4]  The value to the array element can be assigned as  follows- num[0]=10; num[1]=20; num[2]=30; num[3]=40; num[4]=50; Wednesday, September 01, 2010 8 PRADEEP DWIVWDI
DECLARATION OF ONE DIMENSIONAL ARRAY Declaration of an array must specifies three things- Type Name Size ,[object Object],eg, float height[10];       int num[10];      char name[10]; type  variable_name[size]; Wednesday, September 01, 2010 9 PRADEEP DWIVWDI
DECLARATION OF ONE DIMENSIONAL ARRAY character array represents maximum number of characters that the string can hold. for eg,     char name[10]; declare the name array(string) variable that can hold a maximum of 10 characters. suppose we want to read the following string constant into the string variable name. 		“WELL DONE”  Wednesday, September 01, 2010 10 PRADEEP DWIVWDI
DECLARATION OF ONE DIMENSIONAL ARRAY each character of the string treated as an element of array name and stored in the memory as follows-             NOTE:-             when the compiler sees the string, it terminate 	with an additional null character 		  thus, the element name[10] holds the null 	character ‘’. 		   when declaring character array, we must 	allow one extra element space for null 	terminator Wednesday, September 01, 2010 11 PRADEEP DWIVWDI
INITIALIZATION OF ONE DIMENSIONAL ARRAY an array can be initialized at either of the following stages- at compile time. at run time. Wednesday, September 01, 2010 12 PRADEEP DWIVWDI
COMPILE TIME INITIALIZATION the general form of initialization of an array is- the value in the list are separated by commas- eg; int num[3]={1,1,1}; if the number of values in the list is less than the number of elements, then only that many element will be initialized , the remaining element will be set to zero automatically. eg; float total[5]={0.0,1.4,-4.7}; type  array_name[size]={list of values}; Wednesday, September 01, 2010 13 PRADEEP DWIVWDI
COMPILE TIME INITIALIZATION size may be omitted , in such case compiler allocates enough free space for all initialized elemets. for eg,  int num[]={1,2,3,4,5}; character array may be initialized in similar manner. 	char name[]={‘J’,’O’,’H’,’N’,’/0’}; ,[object Object],eg,  char name[]=“JOHN”; Wednesday, September 01, 2010 14 PRADEEP DWIVWDI
NOTE At the time of declaration size must be specified of an array.           int a[]; If we don’t mention the size of an array at the declaration that time we must initialized it-        int a[]={10,20,30,40};  int a[4]={10,20,30,40, 50,60,70};   only take first four values. Wednesday, September 01, 2010 15 PRADEEP DWIVWDI incorrect
NOTE Wednesday, September 01, 2010 PRADEEP DWIVWDI 16 In character array null character placed after the string      char[8]; Suppose we want to store-PRADEEP char  a[20];
RUN TIME INITIALIZATION Wednesday, September 01, 2010 PRADEEP DWIVWDI 17 an array can be explicitly initialized at run time . this approach is usually applied for initializing large arrays. for eg; 	for(i=0;i<100;i++) { 	if(i<50) 		sum[i]=0.0; else 		sum[i]=1.0; 		}
prog23 //Demo for array #include<stdio.h> #include<conio.h> void main() { int num[5],i; clrscr(); printf("Enter five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } printf("The element of array:-"); for(i=0;i<5;i++) { printf("%d",num[i]); } getch(); } Wednesday, September 01, 2010 18 PRADEEP DWIVWDI
prog24 //w.a.p. to find out smallest element in the array. #include<stdio.h> #include<conio.h> void main() { int num[5],small,i; clrscr(); printf("Enter any five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } small=num[0]; for(i=0;i<5;i++) { if(small>num[i]) small=num[i]; } printf("the smallest number is: %d",small); getch(); } Wednesday, September 01, 2010 19 PRADEEP DWIVWDI
prog25 //w.a.p. to arrange the element in ascending order.(selection sort) #include<stdio.h> #include<conio.h> void main() { int num[5],i,j,temp; clrscr(); printf("Enter five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { if(num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } for(i=0;i<5;i++) { printf("%d",num[i]); } getch(); } Wednesday, September 01, 2010 20 PRADEEP DWIVWDI
TWO DIMENSIONAL ARRAY Wednesday, September 01, 2010 PRADEEP DWIVWDI 21 If we want to arrange the element in a row and column format of an array that time we use two dimensional array. In that first dimensional tells about the number of rows and second dimensional tells about the number of columns. For eg-  int a[3][2];              rows            columns
REPRESENTATION OF TWO DIMENSIONAL ARRAY Wednesday, September 01, 2010 PRADEEP DWIVWDI 22 If we want to represent an array for eg- int a[2][3]; col 0     col 1     col 2    			00	  01	    02 Row 0 Row 1 			10	  11	     12
prog26 //write a program to print a matrix #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j; clrscr(); printf("Enter the array elements:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("The elements of array are:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",a[i][j]); } printf(""); } getch(); } Wednesday, September 01, 2010 23 PRADEEP DWIVWDI
Memory representation of prog 26 Wednesday, September 01, 2010 PRADEEP DWIVWDI 24 			0      1       2 		     0 	        1            2
prog27 //write a program for matrix addition #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("Enter the first matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("Enter the second matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf(" The addition of two matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",c[i][j]); } printf(""); } getch(); } Wednesday, September 01, 2010 25 PRADEEP DWIVWDI
Explaination Wednesday, September 01, 2010 PRADEEP DWIVWDI 26 matric a                 matrix b               matrix  c      		                      +                         =
Wednesday, September 01, 2010 PRADEEP DWIVWDI 27 THANKS

More Related Content

What's hot (20)

Array in C
Array in CArray in C
Array in C
 
Arrays
ArraysArrays
Arrays
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
C arrays
C arraysC arrays
C arrays
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Arrays
ArraysArrays
Arrays
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Arrays basics
Arrays basicsArrays basics
Arrays basics
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Array in c
Array in cArray in c
Array in c
 
Array C programming
Array C programmingArray C programming
Array C programming
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Arrays in C
Arrays in CArrays in C
Arrays in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 

Viewers also liked

Programming Merit Badge Slide Show
Programming Merit Badge Slide ShowProgramming Merit Badge Slide Show
Programming Merit Badge Slide ShowNathaniel Swedberg
 
Structures of solid
Structures of solidStructures of solid
Structures of solidArinah Alias
 
C2.1 structure and bonding
C2.1 structure and bondingC2.1 structure and bonding
C2.1 structure and bondingSteve Bishop
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming LanguageAhmad Idrees
 
Structures of solids and other types of bonding
Structures of solids and other types of bondingStructures of solids and other types of bonding
Structures of solids and other types of bondingyizeng
 
Ionic bond,covalent bond and hydrogen bond
Ionic bond,covalent bond and hydrogen bondIonic bond,covalent bond and hydrogen bond
Ionic bond,covalent bond and hydrogen bondEmran Hasan
 
Types of bonding in solids
Types of bonding in solidsTypes of bonding in solids
Types of bonding in solidsMandar Jagtap
 
Object oriented programming (oop) cs304 power point slides lecture 01
Object oriented programming (oop)   cs304 power point slides lecture 01Object oriented programming (oop)   cs304 power point slides lecture 01
Object oriented programming (oop) cs304 power point slides lecture 01Adil Kakakhel
 

Viewers also liked (17)

C programming slide c02
C programming slide c02C programming slide c02
C programming slide c02
 
C programming slide c04
C programming slide c04C programming slide c04
C programming slide c04
 
C programming slide c03
C programming slide c03C programming slide c03
C programming slide c03
 
C programming slide c01
C programming slide c01C programming slide c01
C programming slide c01
 
Bonding in Solids
Bonding in SolidsBonding in Solids
Bonding in Solids
 
Programming Merit Badge Slide Show
Programming Merit Badge Slide ShowProgramming Merit Badge Slide Show
Programming Merit Badge Slide Show
 
C programming slide-6
C programming slide-6C programming slide-6
C programming slide-6
 
Structures of solid
Structures of solidStructures of solid
Structures of solid
 
C2.1 structure and bonding
C2.1 structure and bondingC2.1 structure and bonding
C2.1 structure and bonding
 
Control structures in C++ Programming Language
Control structures in C++ Programming LanguageControl structures in C++ Programming Language
Control structures in C++ Programming Language
 
Structures of solids and other types of bonding
Structures of solids and other types of bondingStructures of solids and other types of bonding
Structures of solids and other types of bonding
 
Computer Programming - Lecture 1
Computer Programming - Lecture 1Computer Programming - Lecture 1
Computer Programming - Lecture 1
 
Ionic bond,covalent bond and hydrogen bond
Ionic bond,covalent bond and hydrogen bondIonic bond,covalent bond and hydrogen bond
Ionic bond,covalent bond and hydrogen bond
 
Types of bonding in solids
Types of bonding in solidsTypes of bonding in solids
Types of bonding in solids
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
Object oriented programming (oop) cs304 power point slides lecture 01
Object oriented programming (oop)   cs304 power point slides lecture 01Object oriented programming (oop)   cs304 power point slides lecture 01
Object oriented programming (oop) cs304 power point slides lecture 01
 
C++ programming
C++ programmingC++ programming
C++ programming
 

Similar to C programming slide c05 (20)

Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Data structure array
Data structure  arrayData structure  array
Data structure array
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
7.basic array
7.basic array7.basic array
7.basic array
 
02 arrays
02 arrays02 arrays
02 arrays
 
Array
ArrayArray
Array
 
C_Arrays.pptx
C_Arrays.pptxC_Arrays.pptx
C_Arrays.pptx
 
Arrays
ArraysArrays
Arrays
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
Array notes
Array notesArray notes
Array notes
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Array
ArrayArray
Array
 

Recently uploaded

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 

Recently uploaded (20)

Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 

C programming slide c05

  • 1. PREPARED BY- PRADEEP DWIVEDI(persuing B.TECH-IT) from HINDUSTAN COLLEGE OF SCIENCE AND TECHNOLOGY(MATHURA) MOB-+919027843806 E-MAIL-pradeep.it74@gmail.com C-PROGRAMMING SLIDE-5 Wednesday, September 01, 2010 1 PRADEEP DWIVWDI
  • 2. ARRAY TOPIC Wednesday, September 01, 2010 2 PRADEEP DWIVWDI
  • 3. ARRAY We use fundamental data type, namely char, int, float, double. Variable of these types can store only one value at a time. In many application we need to store more than one value of data in a single variable that time we use array. ARRAY:- is a fixed size sequenced collection of same data type. In other words, an ARRAY is a special variable that can hold the place for more than one values of same data type at adjacent places. Wednesday, September 01, 2010 3 PRADEEP DWIVWDI
  • 4. EXAMPLE OF ARRAY List of name. List of number. List of students mark. etc. Wednesday, September 01, 2010 4 PRADEEP DWIVWDI
  • 5. DECLARATION AND MEMORY REPRESENTATION OF AN ARRAY int a[10]; 0 1 2 3 4 5 6 7 8 9 Data type Declaration of an array variable dimension Memory representation Index /subscripted number Wednesday, September 01, 2010 5 PRADEEP DWIVWDI
  • 6. TYPES OF ARRAY We have following types of array- One dimensional array. Two dimensional array. Multidimensional array. Wednesday, September 01, 2010 6 PRADEEP DWIVWDI
  • 7. ONE DIMENSIONAL ARRAY A list of item can given one variable name using only one subscript and such a variable called single subscripted variable or a one dimensional array. For, eg- if we want to represent a set of five numbers says (10,20,30,40,50), by an array variable num, then we declare the variable num as follows- int num[5]; Wednesday, September 01, 2010 7 PRADEEP DWIVWDI
  • 8. ONE DIMENSIONAL ARRAY The computer reserves five storage in memory- num[0] num[1] num[2] num[3] num[4] The value to the array element can be assigned as follows- num[0]=10; num[1]=20; num[2]=30; num[3]=40; num[4]=50; Wednesday, September 01, 2010 8 PRADEEP DWIVWDI
  • 9.
  • 10. DECLARATION OF ONE DIMENSIONAL ARRAY character array represents maximum number of characters that the string can hold. for eg, char name[10]; declare the name array(string) variable that can hold a maximum of 10 characters. suppose we want to read the following string constant into the string variable name. “WELL DONE” Wednesday, September 01, 2010 10 PRADEEP DWIVWDI
  • 11. DECLARATION OF ONE DIMENSIONAL ARRAY each character of the string treated as an element of array name and stored in the memory as follows- NOTE:- when the compiler sees the string, it terminate with an additional null character thus, the element name[10] holds the null character ‘’. when declaring character array, we must allow one extra element space for null terminator Wednesday, September 01, 2010 11 PRADEEP DWIVWDI
  • 12. INITIALIZATION OF ONE DIMENSIONAL ARRAY an array can be initialized at either of the following stages- at compile time. at run time. Wednesday, September 01, 2010 12 PRADEEP DWIVWDI
  • 13. COMPILE TIME INITIALIZATION the general form of initialization of an array is- the value in the list are separated by commas- eg; int num[3]={1,1,1}; if the number of values in the list is less than the number of elements, then only that many element will be initialized , the remaining element will be set to zero automatically. eg; float total[5]={0.0,1.4,-4.7}; type array_name[size]={list of values}; Wednesday, September 01, 2010 13 PRADEEP DWIVWDI
  • 14.
  • 15. NOTE At the time of declaration size must be specified of an array. int a[]; If we don’t mention the size of an array at the declaration that time we must initialized it- int a[]={10,20,30,40}; int a[4]={10,20,30,40, 50,60,70}; only take first four values. Wednesday, September 01, 2010 15 PRADEEP DWIVWDI incorrect
  • 16. NOTE Wednesday, September 01, 2010 PRADEEP DWIVWDI 16 In character array null character placed after the string char[8]; Suppose we want to store-PRADEEP char a[20];
  • 17. RUN TIME INITIALIZATION Wednesday, September 01, 2010 PRADEEP DWIVWDI 17 an array can be explicitly initialized at run time . this approach is usually applied for initializing large arrays. for eg; for(i=0;i<100;i++) { if(i<50) sum[i]=0.0; else sum[i]=1.0; }
  • 18. prog23 //Demo for array #include<stdio.h> #include<conio.h> void main() { int num[5],i; clrscr(); printf("Enter five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } printf("The element of array:-"); for(i=0;i<5;i++) { printf("%d",num[i]); } getch(); } Wednesday, September 01, 2010 18 PRADEEP DWIVWDI
  • 19. prog24 //w.a.p. to find out smallest element in the array. #include<stdio.h> #include<conio.h> void main() { int num[5],small,i; clrscr(); printf("Enter any five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } small=num[0]; for(i=0;i<5;i++) { if(small>num[i]) small=num[i]; } printf("the smallest number is: %d",small); getch(); } Wednesday, September 01, 2010 19 PRADEEP DWIVWDI
  • 20. prog25 //w.a.p. to arrange the element in ascending order.(selection sort) #include<stdio.h> #include<conio.h> void main() { int num[5],i,j,temp; clrscr(); printf("Enter five numbers:"); for(i=0;i<5;i++) { scanf("%d",&num[i]); } for(i=0;i<5;i++) { for(j=i+1;j<5;j++) { if(num[i]>num[j]) { temp=num[i]; num[i]=num[j]; num[j]=temp; } } } for(i=0;i<5;i++) { printf("%d",num[i]); } getch(); } Wednesday, September 01, 2010 20 PRADEEP DWIVWDI
  • 21. TWO DIMENSIONAL ARRAY Wednesday, September 01, 2010 PRADEEP DWIVWDI 21 If we want to arrange the element in a row and column format of an array that time we use two dimensional array. In that first dimensional tells about the number of rows and second dimensional tells about the number of columns. For eg- int a[3][2]; rows columns
  • 22. REPRESENTATION OF TWO DIMENSIONAL ARRAY Wednesday, September 01, 2010 PRADEEP DWIVWDI 22 If we want to represent an array for eg- int a[2][3]; col 0 col 1 col 2 00 01 02 Row 0 Row 1 10 11 12
  • 23. prog26 //write a program to print a matrix #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j; clrscr(); printf("Enter the array elements:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("The elements of array are:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",a[i][j]); } printf(""); } getch(); } Wednesday, September 01, 2010 23 PRADEEP DWIVWDI
  • 24. Memory representation of prog 26 Wednesday, September 01, 2010 PRADEEP DWIVWDI 24 0 1 2 0 1 2
  • 25. prog27 //write a program for matrix addition #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("Enter the first matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("Enter the second matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf(" The addition of two matrix:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d",c[i][j]); } printf(""); } getch(); } Wednesday, September 01, 2010 25 PRADEEP DWIVWDI
  • 26. Explaination Wednesday, September 01, 2010 PRADEEP DWIVWDI 26 matric a matrix b matrix c + =
  • 27. Wednesday, September 01, 2010 PRADEEP DWIVWDI 27 THANKS