C Array - Part 2 | C Language Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to nourish technologies so this is famous so in our last session so we discussed the basic concepts of arrays so what is the definition of hooray how to declare the array in how many ways we can initialize the array how to process array elements now we will see some of the examples on array in the first example how to read and how to print array elements okay see here so first we are writing header file header file and then main method inside the main method I am declaring one array already we discussed arrays can be declared either locally or globally so here it is a declaration is a local Declaration in ARR of five I am NOT initializing with any value so if you are not initializing the array with any value then what are the default values garbage values right so here it is how to process the elements that I want to print and check whether all these array locations are initializes with a garbage values are not simple just repeat one for loop and printer right here to print the for loop we need to declare the variable I so declare the variable I index number starts with a zero and here it is a less than 5 I plus plus less than index mean less than the size how to print directly we are giving locations printf printf percentage D percentage D and then ARR of I a error of 0 a error of 1 2 3 4 5 select that it will you sir here it is suppose if you print directly the means our garbage values so it will print one after another one is followed by another then you cannot recognize what is the first element second element third element so I am using here escape character slash in it will send the control to next line so in five lines all the fire base values it will print as an output now it will be clear okay so this is simply how to print array elements now we will see how to find some of all the array elements how to find some of all the array elements okay I am declaring one array and directly I am initializing the values into a are are of size five I am taking five and I am assigning some elements directly 10 20 30 40 50 elements and next I want to find the sum how to find the sum means again we are using one iterator one for loop and we need to check every element we need to access every element that will be added to one value some value right for example first I am declaring I so what is the use of I by which we are repeating the loop index number starts with a zero I is less than 5 I plus plus I plus plus to repeat the for loop we are declaring I from first location to last location all the elements we should add so that is why here it is we are taking right for loop and every time element by element we should collect how to collect j.r.r off I this is collecting the element after collecting where we have to add just add to the variable sum equals to zero you must initialize a variable sum with a zero suppose if you are not initializing by default some value is a garbage value so later all the array elements will be added to the garbage value finally you will get another garbage value you will get what another garbage value so take care of that so here ARR of I value we are adding to some after adding the result we are collecting into variable sum so 5 times it will repeat every time the element will be added to the sum finally we are printing that some printf some value it is an integer so we are printing that some printing that some how it will execute I value starts from 0 to 4 initially some value 0 observe here initially some equals to 0 and I equals to 0 whenever I value 0 I value 0 some value some place yay are off I value 0 plus AR RFI value is at 10 so that will be collected into some we are collecting into some so 0 plus 10 10 will be stored into some in the next iteration whenever I value 1 some value 10 some value 10 plus a ARR of 1 value 20 10 plus 20 will go and store into some it is a 30 in the next iteration some value 30 and I equals to 2 nothing but a error of 2 value is a third thing the value will be stored in to some so what is the some value is a 60 next whenever I value 3 and I value 4 here it is a value for T and here it is a 50 some value is a 60 60 plus 40 will be stored into some so some value 100 next 100 plus 50 150 will be stored into some so value is a 150 so this is okay so five iterations so five times it will execute and the some value finally become 150 so here it will print the value 150 so this is so finding all the elements of array finding all the elements of array using a simple logic by taking the one variable sum and we are repeating one loop and every time every element we are adding to the sum now the next program so what is the largest element in the array among all the elements so what is the largest element in the array we'll see how to find the largest element in the array so first we are taking one array so with some elements here this is array and we are taking some elements 7 13 21 16 9 31 24 index 0 1 2 3 4 5 6 so total 7 elements are there size is a 7 now I want to find out the largest element so we don't know so what is the largest element then how to write the logic simply just find this consider declare one variable large and consider first element is a largest element first element so what is that first element yeh error of 0 now largest element is a 7 what is the largest element 7 now just compare the largest element with remaining elements in the air indexer starts with a 1 to 6 no need to check with the first element sir why because already you considered as a first element is a largest element so why once again you are comparing with the first element wasting the time so start comparing the largest element what is the largest element 7 compare with the index element compare with the index element parallely I am writing logic also observe very clearly suppose large equals 2 yay are off zero now largest element is a 7 next we need to find what is the largest element in the remaining array so repeat the loop from 1 to 6 repeating the for loop I value starts from 1 to 6 is nothing but Y n I plus plus 1 to 7 because index up to 6 right 1 to 7 now every time just check a largest element with the index element compare both largest element and index element index element is a AR of 1 if if you found index element is greater than the large element what is that if index element what is that index element ARR of I what is that ARR of I 13 is greater than the largest element what is the largest element here 7 13 is greater than 7 of course true nothing but you found one more largest element so then what you considered so then just store that index element into largest element you found us more a largest element nothing but another largest element so store that index element into large into large first one is over next I value become increases I value become too so now 13 is comparing with a 21 you found another largest element 21 is the largest element next compared with remain no use fail next 21 compare with a 9 fail next to 21 compare with the 31 yes you found another largest element 21 is replaced with a 31 next 31 is comparing with a 24 again failed so what is the final largest element in the array 31 just print the largest element is a large variable directly printf printf largest element is percentage D large finish this is printing and this is logic this is logic how to find the largest element in the array very easy just first consider the first element is the largest element and every time compare index element with a largest element if you found any index number is greater than the largest element then store that index element into large very simple just like English statements okay so this is so finding a largest element in the array some more examples we will see in the next session for more videos please subscribe to nourish 80 thank you
Info
Channel: Naresh i Technologies
Views: 563,246
Rating: 4.9216132 out of 5
Keywords: C Language, Arrays in C, Srinivas, Naresh IT, Hands on C Language Training, C Language Demo, Online C Language Training, C Language Tutorial Videos, C Language Overview, C Language Interview Questions
Id: e22OJ6YkTRY
Channel Id: undefined
Length: 13min 8sec (788 seconds)
Published: Mon Sep 19 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.