 This is a sample input data file cof slot txt. So, these are the coefficients 4, 2, 1, 3, minus 4, 1, minus 2, minus 2, 3, 5, 3, minus 1, minus 1, 3, 4, 1, minus 2. There is one more line. I have shown the blank line here. It does not matter. Incidentally for the input, you can give as many blank lines as you want or only one blank line or you can even start giving this value after space here. All that depends is how many variables or array elements you are reading and whether you are supplying those many values or not. This 4 indicates that my program will try to read 4 by 4 coefficient matrix followed by a 4 element right hand side. So, necessarily I have to give 4 into 4, 16 plus 4, 20 values in off. I may give just one value 2 on the first line and this value on the second line. But if I am preparing a file, it makes sense to prepare a file in the fashion in which the coefficients on the right hand side will look like. Hence, this is the suggest thermically. These are the sample results. Notice that I am using redirection both ways here. So, dot slash a dot out less than coefficient dot text greater than result dot text. And I know the results are in result dot text. So, I say cat results dot text. You will recall from your first lab that cat is actually a concatenation but effectively we use it to display the results. The other equivalent commands are more and less. The most popular is less. So, you say not cat but less result dot text. Why the word less? Cat results dot text, if it has a huge output it will simply flash through in front of you and you will see only the last few lines of the output. Generally you want to see the first page then go to the next page then go to the next page. So, if you use less command here instead of cat what will happen is that the less command will display one page and wait for you. Only when you press a key it will go to the next page and so on. Anyway this is a short output this is what you will get. Notice however that the values are cluttered 1 0 5 0.5 1.5 etcetera is all right. Here you say 0 1 1.4 minus 2 minus 1 0 0 1 minus 1.0 these values do not appear in an orderly fashion as we would like to see. Notice the values that we had given as input let us go to the previous slide. Very neatly ordered 4 by 4 matrix here 4 right hand side value. Here the coefficient matrix which is printed out by our program notice that we had print instructions c out instructions there does not appear to be properly formatted. However luckily the result is properly formatted that is because we took special precaution. Notice that it is printing this 0th element 1st element 2nd element and 3rd element. But in our c out instruction we had included those funny string which forced me to actually the way this is printed is I first print x and opening bracket as one string. Then I print the value of i which is the index. Then I print the closing bracket and then I print the value of b i which is the right hand side matrix. We would like this printing to be appearing something like this more orderly. So if I say cat result dot x I would like to say 1st column 2nd column 3rd column 4th column and the right hand side all in one. If some numbers are larger so be it they should be provided for that. I have found it useful to indicate such small expectations early enough so that later on when we discuss print f in detail people appreciate why we need some elaborate format. I will briefly describe the second feature which is equally important. In fact in the yesterday's lab program I had included this feature explicitly without explaining it. Many of you would of course know the notion of debugging and the facilities provided in unix or in other operating systems. But there could be some of the colleagues who have not seen these kind of facilities certainly not in unix. What is important is to note that generally no student who attends our course would be aware of these. So it is important to introduce these formally and I have found it better to first introduce them informally as a part of the lab where you will notice that those if not sure kind of segments may not have made any sense to you. However as far as the program execution was concerned the program would have executed proper. What we say is that when the programs are particularly large and complex we are not sure how the program variables are behaving. So what do we mean by testing the program? We run a program and give some test input values. Then we give some test input values program produces some results. If the results are not good typically we trace back and read the segments of our code that we have written. And somewhere we find that I am not sure whether the value of I will be 4 here or 3 here. I want it to be 4 but is it really 4? I am not sure. There is some complication appears to be in computing. The value of this particular another variable here I expected to be this. Is it really that what I would do then? I will say okay I run the program again by putting print of statements or our C out statement. So I may include output statements to print a few key variables at strategic points in your program. These help us in identifying errors. Such statements incidentally are called debugging statements or debugging outputs. Why debugging? A bug is a name given to an error in the program. Debugging is the process of removing those errors. This is standard terminology in software profession. This is quite unstandard for the students who come here. For them the bug has a different meaning. Something which you find on your bed bites you etcetera. So we say that here the error bites us because we do not get the correct results. For that reason it is called a bug. And we have to remove all the errors that process is called debugging. And the way we remove the errors is doing some experimentation for which we need to print something. So such printing of values which may help us identify errors are called debugging pranks. So it is alright. I have a 100 line program and I had some trials. So I introduced print statement at five places in my program. At one place I am printing X at another place I am printing I and J at third place I am printing N whatever whatever. These statements are all across the program. Now after two or three trials my program is ready in working. I am happy. So I give it to my friend saying okay you can do Gauss elimination run this matrix. What will happen when he runs the program? He will of course get the final result. But he will get some funny statements. I is equal to this. K is equal to this. And he will say what is going on? What is this output? Then I realize that look I had introduced those print statements for the purpose of locating errors. Unfortunately I did not remove them at the end. That is the point we are making. Ordinarily once you correct these errors you will like to remove such instructions. But in a large program with many such debugging statements it will amount to a lot of painful work. And it is important to tell our students that while when they do this course they may write just 100 line 200 line programs. Even for their course project they may write 1000 line program which itself is painful. But in real life people will write programs which will amount to 100,000 lines of course. Million lines of course. Team of 100 people working for 6 months. There is a kind of modern program. And although we modularize them, multiple modules will still be of a very large size. In any case the total number of debugging statements that programmers tend to write while correcting their program are fairly large. Removing them is very difficult. The C programming environment under GCC compiler system provides us with a neat option. So in fact in our C programs if we write statements enclosed in a special if statement. What is that special if statement? Hash if xxxx then statements hash end if. This defines a special block in our program. Notice that both these statements start with a hash side. You have already encountered some such thing. Hash includes something something. We have not explained to our students what that is. But later on we will tell them and we have already indicated to them that this is an indication to the programming system to pick out certain standard functions from the library. Similarly we will say this is a special indication to the compiler system. What is that special indication? Ordinarily the special indication works like this. Ordinarily when I am running a program normally any statement inside this block is completely ignored. So as if this block does not exist. That is why if you had compiled the program that we had given you yesterday, it would have compiled normally. What it does is the C compiler simply ignores all the statements in this block in normal circumstances. However I have a mechanism to tell the compiler that look I am debugging at this stage. I am not running my program final for final. I am debugging. The moment I indicate to the compiler that I am debugging the C compiler now translates all these statements also into my final program. And then these statements get executed exactly as if they would have been written without this block. So this is called invoking the debugging option. I note once again if I do not invoke any option in my compiler the program would be compiled normally with completely ignoring these statements. If however I give a command C plus plus minus capital D not sure proc.cpp. So minus D is a debugging flag. This is followed by a token or an invoking. What is that token? I have used the word not sure. You can use it x x x y y y. Error debug or just debug or whatever. How do you relate it to what you have done inside the program? Well inside the program go back here we are said if x x x x end if x x x x actually is a name of any name of my choice. The one I have chosen in the sample example that I gave yesterday is not sure. When I am not sure I want to run these statements. When I am sure I do not want to run them. So instead of x x x x I have said not sure. Please note that I am not permitted to write a sentence with blanks and funny symbols. It is a token. It is like a variable name. So as you can define a variable name and it must not be a normal variable in your program. It is a tag and tag must follow the naming convention that C permits. So I have used a tag called not sure. That means in my program I have said if not sure see out i j sum i j end if. What I am saying? When I am debugging then at this point I want the value of i j and sum of i j to be printed for me to verify things are alright all. This end if says that is all I have to do. So as I said ordinarily the C compiler ignores this block. But if you compile your program with C plus plus minus D not sure proc dot c p p then these statements are compiled are compiled and are executed as part of your program. In a single shot then you have a beautiful facility an elegant facility that I can put any number of debugging statements by using this. I compile it using this while testing it. Finally when I got everything alright I compile it without that option and my program results will not include the printouts contained in the debugging statement. So as a result when finally I crack all errors in my program correct them and hand over that program to my friend saying use it for matrix gauss elimination. When he or she runs that program to actually solve a problem they will the only thing that will be seen is the normal output debugging output will not appear. This in a nutshell are two important facilities one redirection and one compile time debug option. With this I request you to indicate if you have any questions. This time I will follow strictly a protocol because I was told that there are many centers who do not get a chance to interact. So this time we will first go through all the age you said centers one by one and we will follow this up with the centers which are on AVU. I have here a Srinagar Center DOECC Center the moment I see them I would hand over the control to them. Yes I can see them now. Good morning and please do ask your question over to you. Good morning sir. Sir I am Karish from Dwight Center Srinagar sir. Sir the question is that if this gauss elimination method is used we normally take n by n matrix. What if we take an m by n matrix which has a small number of rules and more number of problems. We both have a diagonal range. So how will we solve such a problem? Okay over to you sir. Thank you Tarek. It's an interesting question. His question is that if I do not have an m by n matrix but a n by n matrix but m by n matrix where I have fewer rows and larger number of columns. In such a case how can I use gauss elimination? The correct answer Tarek is that such a system is not a system of n simultaneous equations. Actually in real life when you mathematically formulate models for real life problems you may get under determined a system, over determined system and exactly determined system. An exactly determined system is where you have n independent equations in n variables. And yes you are very right the gauss elimination technique can be applied only in such case. Please remember the keyword n independent equations. For example even if I give n by n coefficients but it so happens that the combination of coefficients represent the following situation that let us say the third row is itself a linear combination of say fifth row or seventh row. In which case third and seventh row are not really representing independent equations and that will result in what you just said your less number of rows and more number of variables. Under determined equation solution is not the job of gauss elimination. In fact those of you who have studied operations research would remember that there you extend it by saying further inequalities and so on and you will get these kind of sets. An over determined set of equation is also possible. You have been given many more equations than what is necessary. Usually you will find that some of them will turn out not necessarily a direct linear combination of some others but a combination subtracted from something else etc. So the correct answer Tarek to your question is that no if I have an under determined set of equations I cannot solve it by gauss elimination as we know gauss elimination now. So therefore we require that we supply n by n equation only for this method to apply as we have implemented it. But I am very happy that you have asked this question this shows some interest in the underlying operations and you and likewise your other friends at other centers I would sincerely request you to go and read the book on numerical recipes it actually discusses all these issues in greater details. Thank you very much Tarek. We now have a request from Vellore so we are going over to Vellore. Yes I can see my friends from Vellore over to you Vellore. We have a couple of questions. Question number one which is declaration statements are better whenever we are declaring a variable all the variable declare at the start of the block or we have to declare at the point of infest use. Yes sir I am at the end of my second question of us is is it possible to use print of statement in C plus this programs or do you sir. Thank you very much. Let me answer both the questions in sequence. The first question applies both to the style of programming as well as appropriateness of programming. Ordinarily we should encourage our students to declare all variables at the beginning. However scope rules which we have not discussed in detail and which I am sure you would like to introduce indicate to us that it is possible to limit the scope of certain variables inside our program. So for example if I want certain variables to be known only inside a particular particular segment like within an external outer iteration or something then I should declare them in the for statement and so on. However the choice between declaring them on first use and declaring them at the beginning my favorite is declare all of them at the beginning. In fact I do not I actually encourage students not to just have declarative statements at the beginning but also have explanatory commands. So for example after they declare arrays they are required to add a command saying what those arrays will represent. When they put in declaration even such as int i j k they are required to put in a command saying these shall be used as index variables for these arrays. When they say sum or sum 1 or sum 2 then they require to explain what that sum is what that sum 1 is etcetera etcetera. This habit of documentation is as important as the place of declaration. So in a nutshell she does not have any rule all depends upon the prevalent programming practice. One of the better practices acknowledged by most people is that unless otherwise required all your variables arrays etcetera should be declared at the beginning of the program preferably with an explanation. Later on when you explain the local scope and the global scope additionally you may indicate that some of those variables may be declared within the block in which they are used and their use is limited. So it is not it is implicitly also at the time of their first utilization. For example when I say for i equal to 1 to something and I have a long iteration if I say for int i equal to something then that i becomes an integer i declaration for that for loop that particular i does not exceed a exist outside and that is perfectly legitimate if you want to limit the scope of that i within that iteration. But generally the variables and arrays which are used across the program in my opinion should be declared at the beginning preferably followed by commands. The second question I am sorry I have already forgotten the second question. Can I very briefly go back again to Vellore and request our friend to repeat that question I should be writing these down. Over to you please ask this question again. Yes sir is it possible to use print of statement. Thank you very much. Print print and scan for standard library functions in C. Thankfully the library functions are also made available as standard library functions in C. C++ actually traditionally has object libraries or classes but by doing an appropriate hash include we can also ask C++ to include conventional C library functions not only scan f and print f but many others including the string library for example. So in a nutshell the answer is yes it is possible to use them. In fact that is probably the only way even in C++ to give a properly formatted output. There is a Raja Rambapu Institute I can now see them. I would like to request them to ask a question over to you. Hello sir my question is graphics.hvider file not supported by Linux operating system and suppose I want to access inbuilt functions which are supported by graphics.h under Linux operating system then how I can able to use that? Over to you. The question is about graphics by saying include graphics.h in Linux why I am not able to do the graphics. Now traditionally the graphics.h library came in the C compiler system which ran on small machines including CPM machines first and then on Microsoft operating systems such as DOS and Windows. Linux operating system has had graphics for a long time the Unix operating systems but all their graphics was built around X-term or X-terminals. Consequently the kind of libraries which are developed for handling graphics on Unix are different. So what you are familiar about the graphics library from your other usage will not work on Linux. While we have not included that as part of this particular workshop but it is a good point that you have made I will ensure that at least one page write up on what graphics libraries can be used in Ubuntu or other Linux variants I will prepare that write up and send it to you early next week so you can try it out. Essentially I repeat once again the graphics system in Linux is built around X-windows system which was developed in the early day. So it is not that the Unix does not support Linux does not support graphics extensive graphics is supported as you can see on your own Ubuntu terminal you have a whole lot of games and other things you have a graphics terminal so there is graphics. The question that you are rightly asking is how do I invoke that graphics from within my C program for which you have to link to library functions from other libraries which are available. There are many open source libraries which are available in your Ubuntu itself the X-window complete library is implemented but I will ask my colleagues to work out a one or two page write up on how what first of all what graphic instructions to use and how to link those libraries with your program. Thank you very much any other remote center there Anna University yes I can see people from Anna University please ask your question over to you. Good morning sir my question is that you gave us a program to estimate the value of pi and you said we have we are taking a quarter circle and then multiplying by four so that we get the whole value but in the program I saw that it was eight multiplied by that formula and still the value was okay but I was not able to understand the logic behind it because I assume that it is still the quarter circle only we are considering when I saw the program over to you sir. Thank you very much actually you will recall that in the lecture I had said that ordinarily I will be looking at the quarter circle but in order to reduce the execution time I was trying to find out how I could reduce it then I found out that the innermost thing was actually looking at the entire circle entire rectangle instead we said that if we look at half of it namely a triangle and examine only the points within that triangle then we will have to do half the computations now while it might appear that that program is same as the earlier program which is looking at the whole square you will notice if you look at the specification for the two outer iterations for i equal to 1 to something for j equal to 1 to n minus and whatever in the program which you actually ran for i equal to 1 to a or 0 to n whatever is there but j does not run from one it starts from i so that means for any one row for any one value of i I examine only those values of j which are i or greater that way I am restricting myself to a triangular portion so while those statements may look exactly similar to you in fact the only difference is that the for instruction for the second loop instead of starting with one it starts with i so in one case it is j equal to 1 in other case it is j equal to i because it is j equal to i you are actually examining only half the points and therefore when you multiply it by 8 you get the correct answers you can examine that that's the only reason in fact otherwise of course as you rightly pointed out the value should have been wrong so the value is not wrong this is what should be happening they have one more question okay over to you i am going to say from 1 minus speaking the question is is there any debugging option then to trace the segmentation fault kind of yours oh over to you thank you very much for the benefit of all other participants I will repeat the question the question is that is there any debugging statement available to help to find out any segmentation fault uh segmentation fault unfortunately is is not a easy thing to detect it does not happen because our values are wrong or our logic is wrong here and there segmentation fault is a very very major issue and there is i'm afraid there is no debugging statement per se which is available the only debugging statement available is that when you get a segmentation fault the program terminates returns to the operating system and operating system thankfully tells us there is a segmentation fault in small programs particularly in embedded systems it is customary that when you get a segmentation fault you get a memory dump of everything and in that memory dump in the olden days people familiar with the machine code and assembly code could actually look at the memory dump and realize what was going on but it is one of the harder errors and in general of course there is no the plain answer is there is no debugging statement specifically targeted to a segmentation fault but what you can do is if you are getting a segmentation fault by introducing debugging statements at various points in your program and running it with the debug option you will at least know that the program has executed this much this much this much and then when you get a segmentation fault you know that the error is between this debug statement and this debug statement so the right answer is no there is no debug statement specifically meant for segmentation fault but yes you can use the same debug facility to roughly locate where the problem is occurring so let's say you have a 100 line program and it is giving segmentation fault after every 10 lines you introduce a debug statement now when you start execution with the minus d flag you will get let us say first print second print third print fourth print and then you get a segmentation fault then you know for sure that something that is executing between these five ten lines between the fourth debug statement and fifth debug statement is a problem and if it is still not clear you can now do a binary search within that again go to the middle of it go up go down fortunately these days computers compile your program very rapidly so within about 10 15 minutes of four or five tries you will be able to zero out even then whether you will be able to locate exactly why you are getting a segmentation fault is not very clear because often the segmentation fault occurs at a particular position but the cause for that segmentation fault is embedded somewhere else in wrong declaration uninitialized variables etc etc sorry for this elaborate answer but good question thank you very much for raising it my only suggestion is use a series of debug statements to isolate the portion of the logic of your program where the segmentation fault is occurring there is a query from uh triple it alabab i can see my friends from alabab over to you very good morning sir this is abhishek swastika from triple it alabab so i have couple of questions from you sir first we are very fortunate enough that we are having their deliberation and in the demonstration and we just you just told us that the c compiler about that how it can we can make debug on to the uh Linux OS right so in our institute we are having a windows operating system and turbo c turbo c compiler so is there any way to pretend ourselves with the debug program we have couple of keys like f7 f8 for manual debugging but is there any options available like you told us in Linux operating system and question number two is so i asked question number two first or i should wait for your answer so what you said the other point is that unless you say over to you i will not start speaking so since you have stopped i will answer the first question uh you see turbo c is an independent system and as you say f6 f7 f8 and the other features in turbo c adequately cover you uh with facilities to debug but if you want to use minus debug option uh i will like to uh state that minus the option is not actually part of linux it is part of the gcc compiler system and even if you are running windows it is perfectly possible to run gcc compiler on windows i will strongly recommend that the new chess compiler system is not merely a compiler it is an exhaustive set of tools and it is in fact extremely useful because it is open source you can use that system when you teach courses in compilers when you teach courses in linux and whatever so a system software courses could benefit because your students could actually see the source code modified see how various aspects of compiler are implemented and so on but even otherwise if you want to utilize features which we have discussed in this workshop it is absolutely easy you just download gcc for windows gcc system is available for windows and once you use gcc for windows you can use all these options uh you can now ask the second question over to you sir we want some clarification pertaining to our group projects uh can it be possible to prepare a question bank on different programming languages like cc plus plus javas c sharp uh and if it is there then how many number of questions we can prepare so as to complete this project over to you sir uh thank you this is an important question i will answer it in two parts first part i will answer now and the second part i will answer at the beginning of the session after take so the answer to the first part is yes you can contribute to the question bank but the question bank cannot be questions in different programming languages please understand that our objective is very focused here we want to create and have material for our students and teachers when they teach first course in programming we have determined that barring a few universities at most places the first course in programming is a course in c programming and therefore the subject portal that we shall be launching on in in september october that portal will be specifically beginning with material in c programming since it will be a portal on computer programming and since computer programming encompassed multiple languages subsequent workshops under this series as well as independent efforts elsewhere in the country could contribute to enhancing that portal to include other programming languages but as far as this workshop is concerned it is a strict no no any activity that you do must contribute to some knowledge addition into basic programming which is offered as first level course and we have decided that it shall be c programming portal what we have said is that while introducing c programming to the beginners we might want to use c in and c out merely so that the confusion that arises because the use of scan f and print f can be avoided in the initial lectures but as i told you all the workshop programs all the sample programs on the sheets on the transmissions that you see which you see in and c out will be substituted by scan f and print f statements when they are put onto the web along with that we will also be putting up these slides so that teachers can use whichever approach they want depending upon the level of autonomy they have coming back to your specific question yes you can contribute to a question bank but since a large number of questions were already made available by the teachers who participated in the pilot program you will be adding value if you do some programming project and that is why i had suggested that you discuss programming projects as possibly but if you think that within the two weeks you will not be able to do a programming project i have indicated that the programming project could be an optional activity once again a programming project in c plus plus or c sharp is completely out of scope as far as this particular workshop is concerned the programming projects must be implemented in c programming language as we have agreed that to be the medium for this particular workshop subsequently in over the coming years we will we will open up the portal for other things but please remember you still have to decide what you will do as part of the mandatory requirement for this particular workshop which is after completion of the workshop within two weeks you have to submit an assignment now that assignment could even be a definition of a project and the design of the project program not necessarily the complete code if you think that your team can complete it in two weeks of course you are most welcome to contribute to the question bank as to how many questions there could be well very difficult to say because it depends upon how long it takes to frame a question if you choose the option of taking up some of your university questions from the previous examination papers then you may be able to put in more number of questions don't forget you have to give complete answers for those questions as well however if you have to set questions and prepare answers it may take longer time you are all teachers so we are not treating this assignment as some rule book kind of thing there is significant freedom and laxity all that i want is that your team should ensure that honest to God you have spent so many hours of work in the subsequent two weeks and if you give three questions that is fine i can only tell you that there was a team from Pune last year in the in the pilot course which had put together something like for 35 or 40 questions and their elaborate answers they really took that job very very seriously and their contributions were extraordinary i don't expect that kind of contribution from every team but i do expect something useful to become part of their submission for the mandatory portion the rest of it is optional and you can do whatever but that whatever has to be related to c programming line i was deeply concerned about the submission of the assignments by the participants i have spent whole night looking at the submissions that came for the last lab first of all only 74 teams have submitted the lab assignments those who have submitted some of them have done absolutely excellent job i am thrilled to find amongst teachers such great programmers who have correctly solved those problems and they have actually put a lot of effort there and i can see the team effort because different things are contributed by different people in some cases multiple options have been given sadly there have been centers from which there has not been in a single submission now this my dear friends is not acceptable i would like to remind all my participants of the following fact forget me and my team here we we are working on the mission project as a dream for last three years we slog day in and day out there is no doubt about it but look at the work that is being put in by your own center coordinators and their team do you know how much time they have spent in preparing for this workshop before you arrived for the workshop do you know that apart from those preparations which i am sure must have taken days and nights they had additionally spent one full week of their valuable time coming to iit do you know how much effort they had taken to explain to all of us coordinators the body of coordinators what are the different dimensions of the syllabus here examination system here and so on so forth why i describe this i would like you to appreciate that if there are so many people working so hard then it is only proper that you come up with an appropriate amount of hardware at least for the workshop i think it is really telling the efforts of your own center coordinators and their team as well as my team here who have worked together please remember this is a dream project please don't treat this as a conventional ist workshop this workshop is not about spending two weeks and getting a certificate this workshop is about rethinking the whole educational system this workshop is about ensuring how my students will become much better programmers than what they are today all of you have heard the cribs from nascom saying our students are not employable they are not good how the hell does nascom say this it says this because our students are not spending enough time in learning thing i am sure we are not the only responsible people for it but i am also sure that if we do not utilize such opportunity to exploit the knowledge pool that we see around us you know at each of your centers not only your team members but the center coordinators their colleagues this kind of facility you will never get i would only urge you to ensure that the submissions are all made the announcement that i want to make is that in this lab today afternoon there is no assignment however at the end of this lab i would like all participants to complete all submissions so not only yesterday's submission but any pending submission that you have from the previous assignments must be completed it is possible that there is so much pending work for some of the participants that they can't complete it by today please make a special request to your coordinators and i request the coordinators to try and arrange some additional time for them if not tonight maybe tomorrow it's a sunday tomorrow maybe you can make some special request for some colleagues to come and open the lab if not tomorrow on monday remember sadly because of the threatened barat one we had to decide because of multiple requests that we shall not have the regular sessions on monday but please note that those of you who have already left their homes and are staying in the remote centers they will be wasting one full day and i feel responsible for that for those of you at least we have not completed your assignments please utilize even that time monday midnight is the upper time limit i am giving for all participants to make all submissions and i will request you to consider this the purpose is not to act like a stern teacher here but the purpose is to ensure that you utilize this opportunity which has been created for you because of very hard work put in by your remote center coordinators their teams my team the government and so on so please cooperate and do that we will now break for team over and out