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

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

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