 Hello everyone. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So today we are having day 15 of this C and C++ coding bootcamp. And in this session I will be discussing how you can implement programs related to 1D array. So in previous session I discussed all the concepts related to 1D array and implemented couple of programs. But in today's session you will see lots of programs I will be implementing for you and you will be learning through those like how basically 1D array works in C programming. So moving forward, so this slide tells everything about me, what I am doing and whatever I have done so far. So I have total 16 plus years of experience and it comprises both education industry experience and IT industry experience which is unique in its form. So which makes me different from other instructors because mostly instructors are part of education industry or maybe part of IT industry but there are very less those worked in both the industries. So that's why I am sharing my knowledge with the community, coming live and sharing things. So moving ahead I just want to share this thought and this thought is available in my every session like consistency is the key so please do regular practice whatever you are doing do regularly so that there will be some results at some point of time. And if you want to discuss any doubt related to C and C++ so join this telegram group and become part of the community and ask questions and I hope all your questions will be answered. And follow Sanjay Gupta Tech School on YouTube, LinkedIn, Instagram, Telegram and all the important links are available in video description as well. So coming on to the topic like 1D array in C programming so like we already discussed all the concepts so if you have not watched that video or stream if you didn't attend live so that is already available on YouTube so you can go and check that recording and you will be able to understand the concepts. So in today's session I will be implementing all these programs so this is our practice exercise for today so one by one I will be implementing a solution for these exercises so so that you can understand how actually 1D array is implemented in C programming and this is very much important so if you are from BTEC background you started your BTEC journey then these sessions are very much important for you and if you are from non-technical background and want to switch to technical or IT background so basically these sessions are very much important for you. So first is count number of positive negative and zero values in array. So yesterday we implemented one program which were counting number of even and odd values so if I if I jump to the solution so this was the solution for that like counting even and odd so I'm just going to erase this and from the beginning I am going to implement that so basically we need to declare an array then for loop counter we will be using I and then for counting purpose like how many positive negative and zero values are available there so for that purpose I am going to create three variables so positive equals to zero negative equals to zero and zero equals to zero so this way I declared three variables positive negative and zero and now this printer will show enter 10 elements then I'm going to implement a loop which will be starting from zero then it will be iterating till 10 and then I plus plus right so inside this loop I'm going to receive values from user so a percent E and then a of I right so this way what is happening like all the elements will be stored inside array so this I already explained you in yesterday's session in previous session like how we can read values of one day array so if you have not watched that recording or video so you can just go and watch and that link is available in the session tracker and session tracker link is available in the description of the video right so this way all the elements will be received now what we need to do we need to apply the conditions so we'll be checking whether a of I is greater than zero if the value which you entered in array at particular index if it is greater than zero then what we can say that number is basically positive number so we can write POS plus plus if it is false for what we can do we can write if a of I is less than zero right so if the entered number if it is not greater than zero so it might be less than zero so in that case what we can do we can write negative plus plus and at last in else what we can do we can write zero plus plus so if if entered number is greater than zero so positive counter will be incremented by one if not then entered number is less than zero so negative counter will be incremented by one otherwise zero will be incremented by one so this way like this program is implemented now once the loop is completed once the loop is completed so all the numbers will be stored in that array and those numbers are also counted like whether they are positive they are negative or zero so all those counted values we can display using printf so we can say positive count POS and D and then POS right so I am just copying it so we'll be having three printf statement positive count negative count and then we have zero count right so all three counts like positive negative and zero will be displayed on UI so now I'm going to run this code will be entering 10 numbers and those 10 numbers will be like some are positive some negative and some zeros so I'm just going to click on run so that I can see what will be the results so I'm entering random values okay so here you can see we have six positive two negative and two zero so basically this hyphen didn't include so I'm going to run this code again actually I mistakenly provided wrong input so one two then zero then minus nine minus eight seven six again zero minus eight nine so this way now positive count is five negative three and zero is two so zero I entered twice negative I entered three times and remaining are positive right so this way the result is coming correct and I hope you are able to understand how actually I implemented the solution right so next is calculate some of two 1d arrays into third area so this is interesting like here with the help of this example you will be able to understand how we can create more than one 1d arrays and how we can use them so basically I'm going to erase everything now here I'm going to create first 1d array of a of 10 size then B of 10 and then C of 10 right so here I'm writing printf enter first array values then again for I equals to zero I less than 10 I plus plus then scanners percent D and then ampersand k of I right so this this loop will be basically reading values for first 1d array now what we can do we can simply copy and paste it so then we need to read second array values so here I'm going to write B of I so basically loop will be same like it will be iterating 10 times but this time all the values which we are going to read will be stored inside this be array so a array will be having 10 different values B array will be having 10 different values now we just need to add them so for I equals to zero I less than 10 and then I plus plus now here what we can do we need to write C of I equals to a of I plus B of I so basically what we need to do in a array whatever value is available at 0th index so it should be added with the value which is available inside B array at 0 index so initially I is 0 so a 0 index value will be added with B 0 index value and both the addition or both the added values will be stored in C array at 0 index right so this way this code will be working and once the addition is available so what you can do you can simply show that value on UI as well so this way like with the help of this printf C of I will be showing the values on UI right now we have three loops first loop will be responsible for reading values for first array second loop is responsible for reading values for second array that is B and third loop is responsible for adding a B and the result will go into C and then through this printf the result the sum will be displayed on UI right now I'm going to run this code so that you can see the results so initially I need to enter 20 values so first I'm entering values for first array so I'm entering all one so first array will be having one 10 times in second array I'm entering for 10 times so here you can see the results are five five is displayed 10 time right here what I can do I can simply display one masses values of third array right so this heading will be displayed and then the result resultant values will be displayed okay so I hope with this explanation with this implementation you are able to understand how we can add values of two 1d arrays and how we can store them into third 1d array right so we have next like we need to print array values in reverse order okay so if if you are entering like natural numbers into into an array like one two three four five up to 10 so if we talk about like how we can print reverse of those values so output should be 10 9 8 7 and so on so the value which is available at last index will display first and second last then third last and so on okay so initial part of the program will be same will be having one 1d array only so enter array values so 10 values will be reading then what I can do I can write a printf which will say array values in reverse order right so here I can copy and paste it so this time what will happen this loop will be starting from 9 condition will be I greater than equals to 0 and then I minus minus so we can we can iterate a loop in decremented order that we already discussed in array sorry in loop related sessions so if you have array sizes 10 so in that case last index will be 9 so that's why in this case loop is starting from 9 and it is decremented to 0 so that all the values will be displayed so here what I'm going to do like I am putting backslash in so that all the values will be displayed in reverse order so initial section like line number 6 7 8 9 these lines will be reading 10 values line number 11 12 13 14 will be displaying all those values in reverse order right so let's see how it will look like when we'll be executing the code so I'm going to enter the values okay there is some mistake sorry instead of scanf we need to write printf so basically I just need to enter the values and it got terminated so here I just copied the code but I forgot to change it to printf so instead of scanf here you need to write printf right now it won't be showing any error so it is executing so I'm entering 1 2 3 4 5 6 7 8 9 and 10 now here you can see the results array values in reverse order so 10 9 8 7 6 5 4 3 2 1 okay so the the order in which you enter the values so values will be printed in reverse order of that okay so I hope with this explanation and implementation you are able to understand how we can print array values in reverse order right next is find out maximum from an array so maximum and this this should be minimum it is typo so basically we need to implement two different implementations one for finding out maximum and one for finding out minimum okay so I'm going to implement that for you so here I'm creating a variable max and I'm reading all the values and here I'm writing max equals to a of 0 so first value I'm entering here now what I'm going to do implementing the loop and it will be starting from 1 and here I am checking if a of i is greater than max so a of i I'm going to assign into max so it is very simple so basically what is happening max will be storing the first value the first value of array will be stored in max now second value onwards we are going to check with the help of this if condition so if second value is greater than max so max is currently having the first value so if second value is greater than max so that second value should be assigned into the max so wherever you are executing this loop and if array value is greater than max variable so that array value will go into the max variable so this happens nine times if your array size is 10 because first value you already assigned into max so that's why we are starting this loop from i equals to 1 right so I hope you understood this and now after completion of loop what you can do you can display the max this way so max equals to percenty and then we can use max variable here so this way whatever values you are going to enter in the array the maximum value whatever is the maximum so that will be displayed with the help of this printer right so now I'm going to click on run here I'm going to enter random values so here you can see max is 45 so I entered 10 different values in in those entered values 45 was the max and you can see max is showing that result as well right so this way code is working fine for finding out maximum next we have find out minimum from an array so it will be very simple so in place of max you can use min so first value I'm assigning as min but if a of i is less than min if if next array element is less than min so what we can do we can assign that array element into min variable and here we will be displaying min so this way you can implement the solution so just just execute this code and I leave it on to you so implement this and test it it will work fine right now last is search whether a particular element is present in array or not so if you have 10 elements in array so you just need to read which element user want to search in that area so there will be two inputs one input will be related to the array and one element one input will be related to the number that you want to search in the array okay so so here we are receiving array then after that we need to write printf enter the number you want to search then scan as percent d ampersand n right so n is the number that we want to search in the array so here I need to implement loop again right so here I'm writing if so what I need to do I just need to compare a of i with n I need to compare a of i with n so if a of i is equals to n it means that number is available inside array that number is available inside array right so if number is found so what we can do we can just break this loop we can just break this loop but how we will be identity identifying whether loop is terminated through break keyword or it is terminated through that termination condition right so here what I'm going to do I'm going to create a variable found and initially it is zero if we found like number whatever number is available into n variable if that is available inside array so found variable will become one and loop will be terminated so if this condition is true then only found will become equals to one otherwise it will remain zero right so after completion of this loop what we need to do we need to check value of found if it is equals to one it means it means number is available so number is present in array as print f number is not present in array right so this way we can check the condition so basically through this loop we are just checking whether number is available or not if it is available then only this if condition will be true and found is equals to one will be set and break I already explained like break is used to terminate execution of the loop so once it is terminated if found is one then this print of this print f will be printed and otherwise number is not present will be displayed so I'm clicking on run and here I'm entering 10 values so I entered values from 1 to 10 now I'm going to search for so here it is same number is present in right so this way whatever codes I decided to showcase to you I did so all these are practice exercises so after watching this live session if you are attending so I would request like in your systems if you if you focus on this practice exercise and if you implement this so it will automatically and improve your logical ability thinking ably ability or implementation ability and if you're watching the recording do do understand the solutions of all the programs and then implement them at your own as well okay so with this note I end today's session here only and in next session I will be talking about 2d array and that session will be happening next week so this week please practice all the scenarios which we which I demonstrated related to 1d array so that you can become expert in that okay so with this note I take your leave and please share a review or feedback and I hope this bootcamp is helping BTEC students and non-technical folks so if you are a beginner then this bootcamp will be very much helpful for you so do share information with everybody those who wants to learn programming and want to become export in this tech industry okay thank you see you next week with new topic