SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere Àhnliche Inhalte

Was ist angesagt? (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
 

Andere mochten auch

Accessibilité commerces
Accessibilité commercesAccessibilité commerces
Accessibilité commercespublimotion
 
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 Mentonpublimotion
 
Session 09
Session 09Session 09
Session 09SamQuiDaiBo
 
Session 05 Final
Session 05 FinalSession 05 Final
Session 05 FinalSamQuiDaiBo
 
Session 15
Session 15Session 15
Session 15SamQuiDaiBo
 

Andere mochten auch (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
 

Ähnlich wie Arrays in C - Elements, Indices, Initialization, Strings, 2D Arrays</title

Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;stringchanchal ghosh
 
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
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functionsSwarup Boro
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfHimanshuKansal22
 
Array assignment
Array assignmentArray assignment
Array assignmentAhmad Kamal
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptNamakkalPasanga
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdfHEMAHEMS5
 
2 arrays
2   arrays2   arrays
2 arraystrixiacruz
 
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 arrayimtiazalijoono
 
19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.ppt19-Lec - Multidimensional Arrays.ppt
19-Lec - Multidimensional Arrays.pptAqeelAbbas94
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Stringsnikshaikh786
 

Ähnlich wie Arrays in C - Elements, Indices, Initialization, Strings, 2D Arrays</title (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
 

Mehr von SamQuiDaiBo

Bai Tap Thuc Hanh Javascript
Bai Tap Thuc Hanh JavascriptBai Tap Thuc Hanh Javascript
Bai Tap Thuc Hanh JavascriptSamQuiDaiBo
 
Hangman Game
Hangman GameHangman Game
Hangman GameSamQuiDaiBo
 
Session 10 Final
Session 10 FinalSession 10 Final
Session 10 FinalSamQuiDaiBo
 
Session 09 Final
Session 09 FinalSession 09 Final
Session 09 FinalSamQuiDaiBo
 
Session 08 Final
Session 08 FinalSession 08 Final
Session 08 FinalSamQuiDaiBo
 
Session 07 Final
Session 07 FinalSession 07 Final
Session 07 FinalSamQuiDaiBo
 
Session 06 Final
Session 06 FinalSession 06 Final
Session 06 FinalSamQuiDaiBo
 
Session 04 Final Sua
Session 04 Final SuaSession 04 Final Sua
Session 04 Final SuaSamQuiDaiBo
 
Session 03 Final
Session 03 FinalSession 03 Final
Session 03 FinalSamQuiDaiBo
 
Session 02 Final
Session 02 FinalSession 02 Final
Session 02 FinalSamQuiDaiBo
 
Session 01 Final
Session 01 FinalSession 01 Final
Session 01 FinalSamQuiDaiBo
 
Html overview
Html overviewHtml overview
Html overviewSamQuiDaiBo
 
Epc Assigment2
Epc Assigment2Epc Assigment2
Epc Assigment2SamQuiDaiBo
 
Epc Assignment1
Epc Assignment1Epc Assignment1
Epc Assignment1SamQuiDaiBo
 

Mehr von 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
 

KĂŒrzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...gurkirankumar98700
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
#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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 

KĂŒrzlich hochgeladen (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍾 8923113531 🎰 Avail...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
#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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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 ...
 

Arrays in C - Elements, Indices, Initialization, Strings, 2D Arrays</title

  • 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