C_58 Program to print Sum of individual Rows and Columns of a Matrix | C Programming

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in the series of learning programming in c we are discussing some programs on metrics or you can say 2d array in this video we will talk about a program where we will find out sum of individual rows and columns like this is a matrix 3 into 3 metrics individual rows means this one row one two and three so some would be for four for this row for this row ten for this row it's four sum of individual column is something like this for this column it's three then ten then five it should print like this individual rows and columns not all the elements not some of all the elements right how we will print this thing that we will discuss in this video first of all drier and this program on the sidebar then i'll practically also i'll show you on my laptop right but before that just want to tell you one thing if you want to prepare for uh you know or maybe if you are preparing for gate 2022 or will be preparing for gay 2022 then an academy is going to start a new batch from 21st of july in this course they are going to cover the top educators will be covering the entire subject the entire slavers of cs and it and apart from the detailed explanation of all the subjects the theory classes some special classes would also be conducted like they'll also discuss preparation strategy some tips and tricks practice questions as well as numericals so that is also going to help you in your preparation classes would be both in hindi and english and notes should be given to you in english so and this is paid subscription actually so you have to pay for it use my code jkl10 to get 10 percent extra discount for this subscription paid subscription and please subscribe before the price hike one more thing an academy is also going to conduct an academy combat it's like india's largest weekly competition for gate here you will get a chance to go head to head with thousands of learners or maybe students who are preparing for gate exam right and that would be on 25th of july so better to take it live compete with the best after this contest after every contest like detailed video solutions would be given to you by their top educators so that you can identify your weak areas and you can improve yourself right so that you can get it right next time and use my code jkl tend to register to unlock this comment so all the links i'll put in the description box of this video you can go and check out so now back to the program first of all we are going to enter this matrix right just declare 3 into a three into three matrix and i and j two loops as well as sum you know two variables for some one for rows and one for column so i am taking suppose s one and s s2 for rows and columns s1 for rows and s2 for sum of columns right or maybe for better understanding i am writing s r here this is for row and this is for column sum of rows and columns right now input or you can say read this matrix i hope everybody is clear with this syntax because we have used the syntax many times right i and j scan f i and j this is to read the matrix three into three matrix 3 columns and 3 rows right now we will access the elements and as well as we are going to print the sum right so obviously 2 for loop i should be 0 i less than 3 and i plus plus right now see i haven't initialized initialized these to zero and previous videos i have told you you have to initialize the sum to zero there are s value why because i am going to initialize it in this for loop because i am going to print i am going to sum the individual rows so after some after doing some of this row right that is 4 that sum of our variable should again be initialized with a 0 for this row otherwise if you will not again initialize it with a 0 then it will do what for some for first row it's 4 then in 4 only it will add these values maybe you are not getting this point right now but it's ok i'll try run this program then you'll get it better right so where we will initialize these sum within this for loop right s r 0 and s c is also 0 right or you can initialize something like this s r equal to s a is equal to 0 right now another for loop j is equal to 0 and j less than 3 and j plus plus now in this for loop we are going to do sum right so sum of rows some are plus a of ig and that would be stored in sr right and sum of column sc plus a now for columns we will do what j i we will interchange it right and that's it now after this for loop after this inner loop we are going to print sum of rho or you can say rather than writing this small i am writing sr equal to percentage d and sorry sr comma sc equal to percentage d in one line line only i am printing both the sum sr comma s c right see i am taking this sr and sc like in capital letters just to make you understand like and these are some of rows and sum of columns but according to the naming convention of that variables you can take it like first variable first you know that letter of this should be small it's better to take small so you can take it in small letters also right or you can take it something like this like sum and row and sum and call like this you can also take right now let me just dry run this program for you then you will get the working of this for loop right see this i hope you got i have entered this one right now see i value is 0 5 i less than 4 3 yes condition to enter here now sr sr and s c srsc both are 0 initialized with 0 within this 4 loop right now j is also 0 condition true yes again enter here now see sr plus a of ij sr is 0 plus a phi j i and j both are 0 a 5 j means this thing 1 so 1 plus 0 that is 1 that would be given to this sr that is 1. now s c plus a of j i now both i and j are equal that is 0 0 so same variable we will access 1 and 1 plus s c 0 and again it will become 1 right now we are in this inner loop now j plus one j becomes one condition two yes again enter here now sr plus a of i j j is now one now s r is one plus a of zero one zero one means this one two so 2 plus 1 3 so 3 would be assigned now to sr now sc plus sc is 1 1 plus a of now j i see it is for column right so that is why means we are accessing we we have to access this 2 right or let me just change it i am just doing it what uh 5 so now we we have to access this 5 for this column that is why i have interchanged rather than i am taking j i so now j is 1 and i is 0 1 0 5 this element 5 so 5 plus 1 that is 6 and now sc becomes 6 right now again j plus plus j becomes now 2 condition true yes enter here now sr plus a of now j is 2 0 2 0 2 means this one so sr is 3 3 plus 1 that is 4 s c plus a off now j is 2 2 0 2 0 this variable you want to access that is 0 so value would be same 6 right now again j plus j becomes 3 but now condition is not true so exit from this loop inner loop and after this inner loop whatever the statement that would be executed so now here obviously we have done some of first row and sum of first column this is 4 2 1 3 and 4 and this is 6 yeah so we have to print this one 4 and 6 that is why within this 4 loop outer for loop i'm printing printing sr now output would be sr equal to 4 and s c equal to what 6 that would be the output right but still we are in this outer loop so now i plus plus now i becomes 1 right now we want to sum of we want that it should give some of this row and this column second one so that is why again we have to initialize this sr to 0 and sc to 0 if you will not initialize then it will take what 4 and 6 so 4 plus and 6 plus so it will not give you correct output that is why now i plus plus i 1 condition true again enter here now that is why i am initializing this sr and sc in this for loop note here i hope now you go to my point now again sr and sc are 0 0 j is again now 0 condition true again enter here now sr plus now sr 0 plus a of now i value is 1 j value is 0 so it will access 1 0 1 0 that is this one 5 0 plus 5 5 so it is 5 sc sc 0 plus j is what j value is a 0 and i value is 1 so it will access 0 1 0 and 1 this one this 2 because i want sum of second column now second row and second column so now 0 plus 2 is 2 now j plus plus now j becomes 1 condition true again enter here sr plus a of i is 1 j is also 1 1 1 that is 3 means it becomes 8 s c plus both are 1 1 that is this 3 so this becomes 5 again it becomes 2 condition true enter here sr plus a of 1 and now j is 2 1 2 1 and 2 this one 1 and 2 5 8 plus 5 is 13 and sc plus now j is what 2 and this is it is 1 2 1 means 2 and 1 so i want to access now this 5 this 5 we are accessing although both value are same but i am accessing this 5 let me change it it is 15 suppose right so now i am accessing this 15 so 15 plus 5 is 20 right now j plus plus j becomes three condition is not true and exit from the inner loop and now again we will print sr equal to 13 sc is equal to 20. now again i become 2 condition 2 enter here and again we are going to initialize it with zero and zero because we now we are going to calculate sum of third row and third column i hope you can try run this completely at your own right no need to complete it here so i guess it's clear to you now the logic how to do some of individual rows and columns right so now let me just show you the output on my screen let me do the practical of this thing so now let me create one more file for you and i'm just writing what row column sum dot c right now write main function and same will take an array of size 3 into 3 and i j some row i am taking and one is some column i am taking right i'm just writing here enter matrix and now i'm just writing the logic to read the metrics within this photo we will use scanf so it should be address of i and j right and that's it now what we will do uh now we will do some right so now again i'm just copying the for loop from above okay so the condition would be same within this outer loop we are going to what initialize what some row equal to both would be zero some row and some column right now i j and here rather than scanf what just use the formula first of all some row plus a of i j and here plus a of j i right and here i am going to print some row equal to percentage d and comma and then sum column equal to percentage d so two variable two percentage the first percentage d will be replaced with whatever the value in some row and second would whatever the value in some column variable right and i guess that's it it should be int main right let me save it and now let me run it i hope it will work say it is asking enter matrix so i am entering here what value one two two two this is second row three three and three this is third row so i think i should print the matrix also then you will get it better let me write down the logic to print matrix rather than scan of here we will write printf and ao5j right slash t and here we are writing printf slash okay now it should print the matrix matrix as i'm printing like this first of all it should print like this so now let me run it center matrix it is asking one one sorry so it is asking enter matrix so 1 1 1 2 2 2 3 three three so matrix is one one one first row so called the sum should be three for second row it's six for third it's nine right now for this column matrix one two three some sum is all the columns should be like same six so yeah it is printing correct output so you can try it at your own and maybe you can modify it like some of those columns as well as some of diagonal you can also print right so that is assignment for you you can print that thing and you can send me that program review you can message me on him on my instagram account right so now i'll see you in the next video with a new program till then bye bye take care
Info
Channel: Jenny's lectures CS/IT NET&JRF
Views: 10,490
Rating: 4.9772081 out of 5
Keywords: data structure tutorials, operating system, data structure and algorithms, jayanti khatri lamba, jennys lectures, jenny data structures, jennys lectures DS, jenny lamba, jennys baby, jennys lectures baby, data structures, C programming tutorials for beginners, two dimensional arrays in c, what is array, data types in c, matrix programs in c, gate cs lectures, ugc net computer science preparation material, c jennys lectures
Id: veODe7OvKIA
Channel Id: undefined
Length: 18min 23sec (1103 seconds)
Published: Wed Jul 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.