SlideShare una empresa de Scribd logo
1 de 18
Arrays Session 7
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Array Elements & Indices ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Defining an Array-1 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],.
Defining an Array-2 ,[object Object],[object Object],[object Object]
Norms with Arrays ,[object Object],[object Object],[object Object],[object Object]
Array Handling in C-1 ,[object Object],[object Object],[object Object],[object Object]
Array Handling in C-2 /* Input values are accepted from the user into the array ary[10]*/ #include <stdio.h> void main() { int ary[10]; int i, total, high; for(i=0; i<10; i++) { printf(“ Enter value: %d : ”, i+1); scanf(“%d”,&ary[i]); } /* Displays highest of the entered values */ high = ary[0]; for(i=1; i<10; i++) { if(ary[i] > high) high = ary[i]; } printf(“Highest value entered was %d”, high); /* prints average of values entered for ary[10] */ for(i=0,total=0; i<10; i++) total = total + ary[i]; printf(“The average of the elements of ary is %d”,total/i); }
Array Initialization ,[object Object],[object Object],[object Object],#include <stdio.h> void main() {   char alpha[26];   int i, j;   for(i=65,j=0; i<91; i++,j++)   {   alpha[j] = i; printf(“The character now assigned is %c ”, alpha[j]);   }   getchar(); }
Strings/Character Arrays-1 ,[object Object],[object Object],[object Object],#include <stdio.h> void main() { char ary[5]; int i; printf(“ Enter string : “); scanf(“%s”,ary);  printf(“ The string is %s ”, ary); for (i=0; i<5; i++) printf(“%d”, ary[i]); }
Strings/Character Arrays-2 Output - The input for the above is of 4 characters and the 5 th  character is the null character The above output is for an input of 5 characters
String Functions ,[object Object]
Two-Dimensional Arrays ,[object Object],[object Object],[object Object],[object Object],[object Object]
Initialization of Multidimensional Arrays-1 ,[object Object],[object Object],The result of the above assignment will be as follows :
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Initialization of Multidimensional Arrays-2
Initialization of Multidimensional Arrays-3 The result of the assignment will be as follows : A two - dimensional string array is declared in the following manner : char str_ary[25][80];
Two-Dimensional Array-1 #include <stdio.h> #include <string.h> void main () { int i, n = 0;  int item; char x[10][12]; char temp[12]; clrscr(); printf(“Enter each string on a separate line”); printf(“Type ‘END’ when over ”); /* read in the list of strings */ do { printf(“String %d : ”, n+1); scanf(“%s”, x[n]); } while (strcmp(x[n++], “END”)); /*reorder the list of strings */   contd…. Example
Two-Dimensional Array-2 n = n – 1; for(item=0; item<n-1; ++item) { /* find lowest of remaining strings */ for(i=item+1; i<n; ++i) { if(strcmp (x[item], x[i]) > 0) { /*interchange two stings */ strcpy (temp, x[item]); strcpy (x[item], x[i]); strcpy (x[i], temp);   }   } } /* Display the arranged list of strings */ printf(“Recorded list of strings : ”); for(i = 0; i < n ; ++i) { printf(&quot;String %d is %s&quot;, i+1, x[i]); } } Example

Más contenido relacionado

La actualidad más candente

02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 

La actualidad más candente (20)

One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Array
ArrayArray
Array
 
Array in c
Array in cArray in c
Array in c
 
Chap09
Chap09Chap09
Chap09
 
Arrays
ArraysArrays
Arrays
 
1-D array
1-D array1-D array
1-D array
 
Arrays
ArraysArrays
Arrays
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
Session 4
Session 4Session 4
Session 4
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
arrays in c
arrays in carrays in c
arrays in c
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
Array
ArrayArray
Array
 
ARRAY
ARRAYARRAY
ARRAY
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
Arrays
ArraysArrays
Arrays
 

Destacado (10)

Test5
Test5Test5
Test5
 
Test1
Test1Test1
Test1
 
Accessibilité commerces
Accessibilité commercesAccessibilité commerces
Accessibilité commerces
 
Ittlgc3
Ittlgc3Ittlgc3
Ittlgc3
 
Charte qualité des terrasses restaurant bar UPCRM Menton
Charte qualité des terrasses restaurant bar UPCRM MentonCharte qualité des terrasses restaurant bar UPCRM Menton
Charte qualité des terrasses restaurant bar UPCRM Menton
 
Ittlgc2
Ittlgc2Ittlgc2
Ittlgc2
 
Session 09
Session 09Session 09
Session 09
 
Session 05 Final
Session 05 FinalSession 05 Final
Session 05 Final
 
Session 15
Session 15Session 15
Session 15
 
Internet
InternetInternet
Internet
 

Similar a Session 7 En

presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
NamakkalPasanga
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
AqeelAbbas94
 

Similar a Session 7 En (20)

Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
02 arrays
02 arrays02 arrays
02 arrays
 
Arrays and Strings
Arrays and Strings Arrays and Strings
Arrays and Strings
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
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
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
Chapter 13.pptx
Chapter 13.pptxChapter 13.pptx
Chapter 13.pptx
 
Array assignment
Array assignmentArray assignment
Array assignment
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
2 arrays
2   arrays2   arrays
2 arrays
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 

Más de SamQuiDaiBo (20)

Test
TestTest
Test
 
T3
T3T3
T3
 
T2
T2T2
T2
 
Bai Tap Thuc Hanh Javascript
Bai Tap Thuc Hanh JavascriptBai Tap Thuc Hanh Javascript
Bai Tap Thuc Hanh Javascript
 
Hangman Game
Hangman GameHangman Game
Hangman Game
 
Session 10 Final
Session 10 FinalSession 10 Final
Session 10 Final
 
Session 09 Final
Session 09 FinalSession 09 Final
Session 09 Final
 
Session 08 Final
Session 08 FinalSession 08 Final
Session 08 Final
 
Session 07 Final
Session 07 FinalSession 07 Final
Session 07 Final
 
Session 06 Final
Session 06 FinalSession 06 Final
Session 06 Final
 
Session 04 Final Sua
Session 04 Final SuaSession 04 Final Sua
Session 04 Final Sua
 
Session 03 Final
Session 03 FinalSession 03 Final
Session 03 Final
 
Session 02 Final
Session 02 FinalSession 02 Final
Session 02 Final
 
Session 01 Final
Session 01 FinalSession 01 Final
Session 01 Final
 
Html overview
Html overviewHtml overview
Html overview
 
Ittlgc1
Ittlgc1Ittlgc1
Ittlgc1
 
Ittlgc
IttlgcIttlgc
Ittlgc
 
Baitap C
Baitap CBaitap C
Baitap C
 
Epc Assigment2
Epc Assigment2Epc Assigment2
Epc Assigment2
 
Epc Assignment1
Epc Assignment1Epc Assignment1
Epc Assignment1
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Session 7 En

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Array Handling in C-2 /* Input values are accepted from the user into the array ary[10]*/ #include <stdio.h> void main() { int ary[10]; int i, total, high; for(i=0; i<10; i++) { printf(“ Enter value: %d : ”, i+1); scanf(“%d”,&ary[i]); } /* Displays highest of the entered values */ high = ary[0]; for(i=1; i<10; i++) { if(ary[i] > high) high = ary[i]; } printf(“Highest value entered was %d”, high); /* prints average of values entered for ary[10] */ for(i=0,total=0; i<10; i++) total = total + ary[i]; printf(“The average of the elements of ary is %d”,total/i); }
  • 9.
  • 10.
  • 11. Strings/Character Arrays-2 Output - The input for the above is of 4 characters and the 5 th character is the null character The above output is for an input of 5 characters
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. Initialization of Multidimensional Arrays-3 The result of the assignment will be as follows : A two - dimensional string array is declared in the following manner : char str_ary[25][80];
  • 17. Two-Dimensional Array-1 #include <stdio.h> #include <string.h> void main () { int i, n = 0; int item; char x[10][12]; char temp[12]; clrscr(); printf(“Enter each string on a separate line”); printf(“Type ‘END’ when over ”); /* read in the list of strings */ do { printf(“String %d : ”, n+1); scanf(“%s”, x[n]); } while (strcmp(x[n++], “END”)); /*reorder the list of strings */ contd…. Example
  • 18. Two-Dimensional Array-2 n = n – 1; for(item=0; item<n-1; ++item) { /* find lowest of remaining strings */ for(i=item+1; i<n; ++i) { if(strcmp (x[item], x[i]) > 0) { /*interchange two stings */ strcpy (temp, x[item]); strcpy (x[item], x[i]); strcpy (x[i], temp); } } } /* Display the arranged list of strings */ printf(“Recorded list of strings : ”); for(i = 0; i < n ; ++i) { printf(&quot;String %d is %s&quot;, i+1, x[i]); } } Example