Chimana provides a grounded, no-nonsense introduction to C that prioritizes practical logic over abstract theory. It is a solid pedagogical resource for those who want to understand the mechanical reality of code rather than just memorizing syntax.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
C Programming Live Coding Session | Functions, If-Else, User Input & Beginner Exercises (2026)Added:
Hello everyone.
Welcome to today's C programming live coding session.
My name is Ezekiel Chimana.
And I'm really excited to have you all here.
Whether you are joining live or watching uh the replay later, you are in the right place to learn, practice, and improve your programming skills.
So, in today's session, we are going to focus on hands-on coding.
This is not just like theory. We will be actually be writing and running C programs together step by step.
So, we'll be covering things uh like um how to input and display output using the if-else statements for decision making, writing and uh and using functions in C programming, maybe [snorts] uh also solving a real-world problem uh using the grading system, something like that.
So, normally, I encourage you to actually open uh your compiler, whether you are using Code::Blocks, Dev-C++, or any other IDE, and try to code along uh with me.
Also, feel free to use the live chat.
Ask your questions there.
Maybe if you are not hearing properly, also type there. Let me know if something is not clear just in that live chat.
I'll try to respond as we uh as we go.
Okay.
So, now what uh what we're going to look at uh today maybe uh is the questions. We are going to start with this one for maybe variables, input, and output, all those things.
Then we look at the conditional statements. And then maybe we look at um functions. And then this uh part where we need to do the grading system, something like that. So, these are part of the questions that we are just going to do on today's what? On today's um uh coding session, just like that.
Okay. So, now let's uh begin.
Okay. So, now let's look at the first question. The first question is saying that, "Write C program that accepts two numbers from the user, calculate and display their sum and product." So, guys, when you are looking at this question, you need to first understand the demands of the question before attempting the question. Guys, be it in an interview or maybe it's in an exam, what you really need to do first is to understand the what? Is to understand the questions and the demands of the questions before you try anything.
Is that so?
So, let's look at this. You are being asked to accept uh to accept two numbers from the user.
So, the first thing is to i- i- i- is to think about uh then how am I going to store these numbers, all those things, something like that, right? So, you want to store these numbers.
Is that so?
And then after that, what do you want to do?
Right?
Yeah, then you want to do the calculation, and then you need to display the sum and the product. So, if it was me coding this, what could I do on this one?
Okay. So, let me just go on to So, I want to go on to the Dev-C++ compiler. That's what I'm using here.
So, if you look at this Dev-C++ compiler, um I already have this basic C program structure with this hash include stdio.h for me to be able to use the stdio, which is the For me to be able to use the printf and the scanf statement, right?
So, without this header file, you are not able to print to screen and maybe to take the input that you want from the user, right? And then I've got the main function, and this main function is where my program starts to what? To execute. So, I always need this main function, and this return zero so that I will stop my program whenever I am done with what I'm supposed to do. So, let's get back to the question. The question say, "Accept two numbers from the user."
So, what do I need? I need variables to store what? To store two numbers. So, let me just start by creating maybe num1 int num1, which is a variable to store any integer there. And then I'll also create another variable called num2 for me to be able to store the second va- for me to be able to se- to to store the second value. And after doing so, now what do I need to do? I need to accept two numbers from the user. So, how do I do that? First, let me just say I So, I'll print to the user to say that uh please enter what?
Enter the first number, something like that. Enter the first number.
Right? Then let me just put a slash n there to skip a line so that I will jump a line whenever uh like whatever that is going to be printed next will be printed on a new line. That's the slash n there. So, this is statement will just print to screen and do nothing. If you look at it, if I run this, it will just print to the screen, and nothing else will follow up.
So, what do I need for me to be able to take the the the the number there? I need to write what you call the scanf function, which is the function to to request any input from the keyboard or from the user, right? So, here I need to use the format spe- the format specifier percentage d for me to be able to take the integer, just like that. I need to use the format specifier percentage d. Is that so?
Okay. So, after that, what do I need there? I need to use the address operator. I need to use the address operator, right? And then I'll store the value in num1. So, like this, and then you need to terminate whenever you reach the end of a line, right? Is that so? So, if I run this, I'm going to be able to take this first number, maybe it's a four, something like that, and then I'll store it. So, the next thing now is to take the second number. So, it's just a repetition of what we have done. Is that so? So, I think it's something which is actually not that hard to do, but um you just need to to to know what you are doing. So, here I will just repeat the same printf, right?
Then I will just say, "Enter the second number." Is that so? Enter the second number, then I'll put a slash n there.
And then what do I do there? I write a scanf again to take that number, then I use the format specifier percentage d, which is a placeholder, right?
And then I'll put the address operator so that we'll be able to write at the address of num2, something like that.
So, after doing this, right? Which means I'll be able to take the first and the second number.
Right? So, the first demand of the question, we are now done with the first demands of the question. And then the second demand was to calculate and display their sum and product, right?
So, now I want to declare and um and um Now Now, I want to declare maybe some variables that I need to use here. And then I will do the sum, and then I will do the the product. Is that simple, right? So, here because I want to do the sum and the product, maybe let me just also add some of the variables here, which is the sum and uh the product, right? Is that so? Sum and product there. So, what do I need to do now?
Is now to calculate the sum, right? So, sum will be equal to sum, then I'll use this addition, then I'll write sum there, and then I'll terminate, something like this. So, what I'm doing is that I'm adding two variables, which is this sum and this sum.
So, not sum, sorry. I need to add num1 and num2. So, I'm adding these two variables. So, it's num1 and num2, just like that. So, I'm adding the number that two numbers that was that were entered by the user. So, this one and this one. So, I'm adding these two values that uh uh that have been actually typed in by the what? By the user. So, I will do so on product as well.
Product will be equal to num1 times num2. For multiplication, guys, you use the asterisk or that star that you have on your keyboard, something like that. That's the multiplication that you use, right?
So, now let's look at um After doing this, now the final demand was to display the sum and product. So, what do I do now? I need to print out the sum, right?
Sum or maybe let me just say sum of Maybe let's just make it simple, right?
The The is Let me just say the sum is I'll get back and maybe do what I wanted to do, but this one is just good. The sum is then I'll put maybe percentage D there.
And then I'll put when I'm saying percentage D what it means is that this one is a format specifier or a placeholder where the value is going to be printed or where the value is going to be what to be printed. So here it's what? It's the sum, right?
So what it does is that it is going to take the value of sum and then it will place here. So it will be like the sum is something like that. So let me just test before we do the before we print the the product. So I'm going to put a three and a four. So the sum is seven, something like that. So let's just do the same with what? With the product there.
So we say print F something like this.
Right?
Oh, sorry. So here I'll say the product is right?
Then here what do I do? I also do a percentage D there.
And then I need to put um So here let me say product.
I'm saying that I was supposed to put a {slash} N here so that the product whatever this statement will be printed maybe after skipping a what? A line.
Because I didn't do so I want you to see what will happen there. Right? So let me just say here I'll put a four and a five there. So I'm getting that the sum is nine and then the product is 20. So if you look at it here I didn't skip a line. So I need to put a {slash} N here so that we skip a line whenever we run this, something like this.
So let's see what I'm going to get here if I put a four and a five. So now it's what? The sum is nine and the product is 20. So if you look at it now let's go back to the to the question. The question I'm saying write a C program that accepts two numbers from the user and then calculate calculates and displays their sum and product. So if you look at it this is what we have actually done, right? And you are good to go and you are good to to score all the marks. All right, then then let me just get back to what I've said I wanted maybe to make it more spice like here I can say the sum of maybe percentage D and percentage D is something like this. So what I'm doing is I'm I want to say the sum of num one and num two is what we're something like that. So what you need to do you need to match this order of this placeholder as well on the on the variable. So I'm going to say the sum of num one is this variable. So is is this variable num one there since we've stored that value here and then we say num two there.
Something like this. So let me just run this. You could also do the same on the product there.
It's just good, right? Just good in that way. So if I put a four and a five see the sum of four and five is nine, something like that. So we could do the same with what? With the product, right?
So here the product of you say percentage D and percentage D. These are format specifiers is something like that. Then we put num one then num two, right? Just like that.
So I need a comma here as well as well.
Yes, then let me compare and run. So I think that's all on this question. If you are able to do this then you are able to score all the what? All the marks. So the sum of four and five is nine and then the product of four and five is 20. That's all that you need on this first question, right? So I don't know if you've managed to get it very well, but you can also try on your on your side as you are coding.
But what is very important what is very important is to make sure that you meet the demands of the question. How?
Understand them first. That's so. Okay.
But if you have any question guys so far you can maybe type it in the live chat and then I'll be able to pick it on the live chat and then I'll respond, right?
That's the best way to to ask your questions. Uh please do so. Do not just let it go, right? So that way also it will be interactive, right? So now let's look at um the question two which says um uh where we are looking at conditional statements, right? The if whatever if else whatever all those things. So for us to be able to make a decision for us to be able to make a decision, right?
in programming we need these what you call conditional statements. You can't be just coding and coding without making a decision. There is a point where you need to make decision like what we do in real life, right? So here we are represented with this question which says write a C program that accepts a student's mark then displays pass if mark is greater than or equal to 50 and then fail if mark is less than 50. Also display invalid mark if the mark is less than zero or greater than 100. So you need to uh to read and understand the question very well. You need to read and and understand the question very well, guys.
Why? So because some of the demands that that you get here it's easier to to maybe just miss it, right? If you do not read very well. That's so.
Okay, so now let's look at this, right?
Uh if we look at it very well we are being told that here we need a C program which is going to accept a student's mark. So that's the first thing that you need to write down. Okay, so I need to accept a a student's mark.
Then what's next? Then I need to check if the mark is greater than or equal to 50. If it is greater than or equal to 50 then I'll say it's a pass.
Right? So you just display pass.
Just as simple as that. And then if mark is less than 50 you just display fail.
And there are these quotes. That's what it is saying there. Also display invalid mark if the mark is less than zero or greater than 100. So what I would suggest here first is to accept the student's mark.
After that is to check if the mark is actually valid. If it is not just say invalid mark, right? And then after that you go on to check if the mark is greater than or equal to 50 or if the mark is less than 50 and then you display what you are supposed to display, right? So that's uh what you are supposed to do.
Someone is saying um can this be recorded because I missed the first question. Okay, so just after this live uh session uh the recording will be available. The recording will be available for for replay.
Okay, so now let's look at um this. How do you respond to this, right?
So let me take out all these. I just assume that everyone is able to create a new project um in Dev-C++ or in your IDE. That's why I just started by just coding, right? So now let's look at um this question, right? So the first thing is to accept the student's mark, right?
So here let me just say int mark, right?
Just like that. And then I'll ask you to enter the student mark as it was required. Accept a student's what? Mark, just a single mark, something like that.
So how do you do it? Print F there.
Then I'll say enter student mark or something like that.
Okay.
So here let me put a {slash} N and then I'll put this.
And then I have a scan F there.
Right?
I have a scan F.
Then I'll do here I will say scan F percentage D.
Then here I need the address operator to store or to be able to access this mark, right? Let's compare and see if we're if everything's going to run.
Yes, and then maybe I'll put a 40 there.
Nothing is happening. Why? Because we didn't make the decision, right? So now what we need to do next? If you go back to the question, we want to display pass if the mark is greater than or equal to 50 and fail if the mark is less than 50.
At the same time we want to display invalid mark if the mark is less than zero or greater than 100. So the first thing let's check if Right? So for the syntax of an if statement you just write like this, right? So there is if here and then here there's a condition and then here a block of code which is going to be executed, right?
>> [snorts] >> If the condition is true. So let's just check if mark is what? Is less than zero, right?
If mark less than zero and so we use this and logical operator, right? Let me just put this space here.
There wasn't going to be an error, but to just make it look good, right? So with this and right, it's a logical and operator which requires both conditions to be true for us to execute the block.
So I'm going to say if mark is less than zero and if mark is is less than zero or if mark is greater than 100. So what does it do? It checks if the mark is less than 100. If if the mark is less than zero, sorry. So if it is less than zero it will just print invalid mark.
Also it will check if the mark is greater than 100. Then it will just print invalid mark. So it's just a matter of try to join two conditions.
Otherwise we're going to write if mark is less than zero, write this and also then we do another if statement or an else if statement and then we check if the mark is greater than 100 and then we also print invalid mark.
Something like that. Instead of just doing all those things, you could just use the end operator here. What does it do with this? We check if the mark is So these conditions needs to be or we can use the or here. We just need one of these to be true, not both of them. So if the mark is just less than 100 then we print invalid mark. Also if mark is greater than 100, then we print invalid mark. Something like that. So there's no need of using the end operator here because the end operator you want both of them to be true and it can't be because we're just using this one mark. Something like that. So you need the or operator. We just want one of these to be what? To be true. That's all.
Okay, so let's look at um at this.
Uh now you need to print, right? So use print F.
Then what do we do here? Um Here we just write like what we instructed, invalid mark, right?
No need of you try to be innovative.
You're being told that print or display invalid mark, right? So now let's test this and see.
Now I want to put maybe a mark which is uh minus three and I'll get invalid mark.
Right? Then now let me test and put maybe a 1,000 there. I'll get invalid mark, right? And then maybe let me test and put a mark like a 55.
Then I'll get nothing. Why? Because the question now is not yet meeting the what? The second demand. That's all.
Okay, so let's look at um let's look at um the the second demand which is the pass and fail which is if mark is greater than or equal to what? Or equal to 50, right? So let's start with that one. All right. So here we checked this and then if this actually failed, now we have an else if statement, right?
And then with this else if statement, what are we going to do here? What we're going to do is to check if mark is greater than or equal to. That's how you write greater than or equal to in programming.
If mark is greater than or equal to 50.
What do we do if mark is greater than or equal to 50? We just print F and say pass, right?
So if you look at it, now if I run this, we are almost there. If I run this, I'll get um if if I put a 55, I'll get a pass, right? But what if I put something less than 50 which is a 30. I should get a fail, but I'm getting nothing. So what do you do now? Because we already tightened up our range, the the one which is less than zero and the one which is greater than 100 and then the greater than or equal to 50 what it means is that the only possible whatever, the only possible mark that you would do uh that we need to capture now is the is the one which is less than what? Less than 50. So which means if I just put else here, I'm okay.
Right? I could just say else print F fail. Something like this.
This one will be correct. Or maybe you could just put an else if there, but it's not really necessary. What is good here is to just put the what?
The else part. Why? Because we know that any mark which is less than zero or greater than 100 is going to be captured here first and then it stops there.
But uh if you put something greater than or equal to 50, it's going to print pass and it stops there. But if you put something between zero and 49 or and 50, something like that. Zero and 49, something like that. Uh inclusive, then you get a fail.
Just like that. So that's how you deal with this. So maybe now I can try and put my 30 there and then I'll get a what? I'll get a fail. So do not try to be innovative, whatever. All this this is what you can do. But also remember the other thing, guys.
Whenever writing your code, please do not forget to put comments.
It is very very important. Just put comments to show that you know what you're doing. To show that you are explaining your code or you can explain your code. You can stand by your code, something like that. That's all. So here just need maybe to comment here. This is how you put a single line comment, right? So here you are declaring variables, something like that.
Declaring variables.
So that uh whenever if it is someone who's going to mark really knows that oh this person actually understood what he or she was doing here. Maybe printing out uh maybe printing out uh to user or prompting the user to enter a mark or something like that, right? Print out to what? To user, something like that. Then here maybe uh you are accepting what? Accepting a value from the user. These are just comments. They are going to be ignored by the what?
They are going to be ignored by the compiler whenever you are whenever you are compiling and running your program, something like that. So it is just going to be saved just like that way, right? So if I'm going to put an 80 which is most of you are going to get then you get a what? A pass, something like that, right?
So that's all on this question. I don't think there is much that I can add on this one.
Otherwise you can keep on commenting.
Maybe you can comment each and every line or just the block like here this if one this the if statement. You can just comment it at once, something like that.
Which is the if um condition there maybe to test or to check which is the the this part, the first part here.
To check for invalid mark, something like that. Da da da da, just like that.
Okay, so now let's look at the third question which is on functions. So when it comes to the issue of functions, guys, I think you need to understand what is a function C, the function prototype and maybe how to declare function and call a function.
So I did it in some of the tutorials. If you have any challenge, maybe you could also go and watch those tutorials. Here I'm trying to just maybe do a a revision of this, right? So if you look at at a function, you are looking at that those group of statements that can execute a specific what? A specific task. That's what you call a function, right? And then there's what you call a function prototype where you just maybe write a function without giving it the actual full definition of that what? Of that function. Without putting the actual code which is going to be executed. It's just some sort of way of just register a function in a C programming, right? So that it will be checked against whenever it is now running, something like that, right?
So now what you want to do is to write a C program that defines a function to calculate the square of a number. Square of a number is just the number then multiply itself, something like that.
Multiplying the number by what? By itself. That's the square of a number.
Like two squared is just two times two, something like that. So you want a function that finds a square of a number, just like that. That's what you want to do.
That's all.
So how do you do this, right? So the first thing first things first you need to get the demands of the question and then you plan accordingly, something like that.
So let's look at this. What you need to do is whenever you are doing functions in C programming, there are two ways that you can do it, right? You do function prototyping, then you create the function and then you call the function.
Three steps. Or you can just create the function and then you call the function which is two steps, something like that.
Or is what? Is acceptable, right?
But I always encourage you to do function prototype first and then create the function definition or which is giving the function the actual code that you want and then you do what you call function calling and then we know that the function is going to turn this or whatever what is what is going to happen, right? So now let's look at the function that you want is to calculate the square of a number. So let's go with say with any with a function that will return an integer something like that. So whenever you're creating a function prototype you need to put the return type first. What is it going to return? So because I'm going to do what you call function prototype I'm not going to give the actual code. So I always do it in between the preprocessor directives.
These are preprocessor directives these header files or something like that and the main function in between there that global space that's where I put the function prototype, right?
So here I will say because I'm not actually told the exact name of the function so I can give the name that I want, right? So let me just write square just like that and then because I want to calculate the square of a number. So I needed to take the parameters. There's what you call parameters when it comes to functions, right? Those values that you wanted to operate on or those values that you wanted for you to be able to do that task something like that. That's what we call what parameters. So here I will say int a or maybe int num for the number that you are going to get. So this was just going to take one number and then we we multiply that number by itself and maybe return the result of multiplying something like that. Is that so? Then we are good to go. So this is what you call the function prototype. We are just registering the function nothing much that we are going to do. So if you have got any question do so by typing in the live chat there maybe if you have somewhere you need clarification or maybe question something like that so that I will help you. So now let's look at the other the the the second part that you do now is to actually code the function. Is that so? So here what do you do now? You just repeat like what you've done here but now you give the function what its body and now you do the actual things that you're supposed to do. Is that so? So here I will just say int which is the return type. This function is going to return an integer which is the square of that number, right? So I will I will repeat int square, right? And then like this but here I'm supposed to take a what? A number something like that int num and then what do I do here? The next thing that I will need to do is to actually find the square of that Is that so? Of that number. So I'm going to return num times num which is the square of that number. So this function is going to return the multiplication of a number by itself. Then we are good to go. But now because our code is not going to call this function if I run this the code is just going to do nothing because there is nothing in the main function.
So the the the the the following thing that I need to do here is to just call the function to do what? To do what it's supposed to do and maybe I'll just print that which is just an extra flare there so that I will be able to confirm that um is it going to you know give me the right output. So here let me just say uh what I want to do here I can just declare and call the function at the same time like declare maybe result here then what I would do is calling a function you just need to write the name of the function, right?
Which is square.
Is that so? Square like this and then here you need to pass the actual value, right? So because here the question didn't tell us much about this value maybe asking the user or whatever didn't tell us much about this. So it will be fine if I just put a four there. What does that four mean? It means that I'm passing this four to this function and then this function like here it is going to be a four then it will put a four in this num and then what does it do? It will multiply four and four and then it will return the result. Where does it return? It will return the result here and put that result in this result something like that. So let me just print that result.
So here I will say uh maybe the square of uh I do not have the actual number here uh for me to to write it. I do not have the actual number because it's not the variable. Let me just say the square is then percentage the otherwise I would and then it's not also it's not the correct answer if you try to print it here because here it's supposed to just return the um it will it will be still correct because here it's not that too much restricting. Uh the question is not too much restricting you to do maybe exact something something like that. So here I will just print result. So you could also opt to just print the result here you just calculate and print something like that but this way I think that's the best you can do it where you can just calculate and then it will return.
That's what it's supposed to do.
Just like that. So let me see if it is going to tell me yes. So the square is 16. 4 * 4 is actually is actually 16 something like that. So like what I was trying to do here maybe I can declare a variable here but otherwise that's what you need to do guys. I'm just trying to add a flare so that you to be something nicer than what you've done. So here I I would say int num um as a variable there that then I will print out printf enter the number to find its square something like that.
Enter number uh to find its square something like that.
All right.
And then I need to put a slash in there to skip a line, right?
And then what do I do? I write a scanf there.
Then I will say then I will say what do I what I will do there? Then I will say percentage D. I was reading someone was saying square root function. No here you were not being asked to to find the square root but you are being asked to find the square of a number not the square root of a number. Is that so? That one is a different case, right? That that needs its whatever special code something like that. But here what you what you want to do is is finding the square of a number. So this is a function that we've created to find the square of a number. Is that so?
So here I will put the address operator there and then I will say um num there, right? And then so what happens is that whenever I do this, right?
Someone enters a number we capture the number we pass it to a function then what does it do? It jumps here and then it will calculate the square and then it will return that square and then just like that then it will print the result something like that and then we are good to go. So here we can now write that the square of here the square of then we put percentage D there. So you could say the square of num is then we take the value from the result. So let's see if it is going to work then I will put maybe five there it will say the square of five is uh is 25 just like that. Then we are good to go. So that's how you play around and able to what?
To code this question and then you are good to go. I don't know if it is hard but I think it's just simple. What you just need to do maybe is to make sure that you follow What you need to do is to make sure that you follow these simple um these simple instructions, right?
That that that's what is very very important. First read and understand what you are supposed to do. Is that so?
First read uh what you are supposed to to to do and then you you understand the demands of that question. Is that so?
I think that's what you need uh to do there. So maybe the next thing is to look at the second question but I don't know if there are any questions just put um just put them on the live chat. Is that so?
Maybe that way it will it will make it interactive. Is that so?
Okay.
So for those that were asking on on the issue of um I'm sure there was a question. I want to close this.
It was on there was a comment talking about the square root. If you want to do the issue of a square root it's a separate issue there. You need a library the math.h library. It's a header file library. It's it's a it's a library which is already there which you find you a square root of a given number. And uh the function to do so, which is in that math.h library there, is the square root, which is the sqrt.
So, you just call that and then you pass that value. Like here, where we are saying square here, this function here, what you would do instead of calling this function that we have created, there is a math.h library, something like that, that already have I don't know if I could just quickly do it here.
Uh include something like that.
math.h something like this. And then what you need to do is to just to call sqrt something like that. That's how you call the function sqrt, something like that. So, what does it do? This function needs to to print us the square root of that number, something like that. So, if I run this and then maybe let me put a 16, something like that, and see, then I'll get the square It should be now the square root of 16 is what? Is a four, something like that. So, it's now a matter of just using the function which is already there. But if you look at it, that wasn't in the demands of the what?
Of the question. That wasn't in the demands of the what? Of the question.
I'm just doing so that maybe if you run into a question that needs you to find the square root of a given number, something like that, that's how you do it.
So, you you you see how these um uh pre-whatever functions that you already have um in the that comes with the with the C or with the that comes with with the C uh programming language, they are very handy. Here, we wanted a a function to find a a square of a number. You find out that we have write it all these codes, all these codes. But now, when you want to find a square root, you just need to import the math.h there and then to write square sqrt and then you put a value there, then it will give every, something like that. So, that's how you make use of those functions which are already there. You do not need to know how is it going to calculate the square root. You just give it a value. It will calculate for you and then it will give you the result, something like that.
Okay, so someone was asking, should do the function return the square value or should it also handle user input and display the result? For this question, guys, it's up to you uh on how you are going to do that. But at the end, the function should calculate the square of a what? Of a number. So, you can choose to handle everything within this function, and then you just call it, and then all these whatever we have here will be within this function. There's no problem there.
What What I propose is just a neat way, maybe, to do it or something like that.
But there's no problem. Why? Because the question the demands of the questions are not that too restrictive. So, just feel free to handle it the way you would want. But the major thing that you need to do is to be able to calculate the square of a what? Of a number. Also, do not forget to put those uh comments as well. Is that so?
Someone What about a function that uh display the sum of two numbers? If you want to have the function which it displays the the sum of two numbers, just the same. I think we have done a question where we would where we would do maybe display the sum of what? Yes, we did a question here, which was saying that um accept two numbers from the user, calculate the and display their sum and product. So, if you want to do it as we did it within the main function. But if you want a special a special function which will be doing that, what do you do? You create a function to add two numbers, maybe this one. Uh you call it maybe add whatever you want to to name it, right?
Or maybe uh sum, whatever that you want to do. Because you want to add two numbers, then it needs to take what? Two numbers, something like that. num1 and maybe num2, something like that. da da da da And then what do you do here? We Let's just change it here to maybe So, we put Sorry, here it should be what? add. So, here you have num1 and num2. It's just simple like what we have done. So, here what do you need to do is just to add num1 and num2. Something like this. So, this function will just add two numbers and then it will return the result of those two numbers. So, here we'll be just saying instead of just taking one number there, then now we need to take what? Two numbers, right? Is that so?
And um maybe enter the first number, something like that.
Enter the first number.
Because it's a question that was that was in there. Here, I need num1 and num2 there.
Then here, I'll take the value and put it in num1.
And then let me take the second number there.
Right? And then I'll put it in what?
Uh second number.
Is that so? Second number, then I'll put it in what? In num2.
Is that so? Yes, we are good to go. And then here, I'm going to call the function called what? add. So, whenever I do this, here I'm supposed to pass two values. Is that so?
Then I'll put num2. So, the first value that you have we entered here is going to come here, then it will come here.
The second value, it will come here, then it will come here. And then what does it do? It will just add and then it will return the result. Then we store the number that is being returned here.
And then what do we do? Then we print the result. So, here we say the sum of Now, it's no longer the, but it's the sum of %d and maybe %d is Then here, we'll put num1 and num2.
And then we are good to go.
Then the result there. So, here Let me put the space, just like this, and then let's test and see if it's going to work. Oh, there is an error which says unknown type name num2. What have I done there?
Let's look at um Maybe Where is this error coming from?
Line number three.
Let's look at this. Maybe there's somewhere I didn't declare the variable very well.
Oh, maybe I don't know what happened there. This is line what? Line three.
Okay, sorry. It's just about here. I didn't declare I'm supposed to give the data type. So, that's where the error is coming from.
Just like that. I was supposed to give the data type here. So, guys, that's the importance of uh as well as here.
That's the importance of um having these function prototypes as well. It just check all those things, right?
Thank you for that prototype. There is Thank you for that. That That That's where the error was. That's where the error was. So, here if I put a four and maybe five, I'll get that the sum of four and five is what? Is nine. Okay, so we are good to go. That's how you do a function which is going to you know, add two numbers and then return the result, something like that. Okay, guys, so you can you can play you can play around with all these code, whatever, and see if it is going to work for you.
Otherwise, what you need to look at is this uh last question of this I was planning to do this maybe in an hour.
So, let's see maybe 1 hour to 1 1 hour 15 minutes. I don't know if you are going to manage that, but um if I didn't, I'm sorry for that, but let's look at uh the question two here, which is uh also Sorry, not question two, but question four, which is looking at the student grading system. Now, we want to have a student grading system. But on this student grading system, it is saying write a C program that accepts student name.
Right?
And then someone was asking, what about declaring and defining the function at once?
Okay, if you want to declare and define the function at once, I don't know if I declared everything. What you need to do is just to omit this one.
If you just remove the function prototype, then you are just declaring here everything. So, you'll be declaring the function at the same time you'll be doing the function definition. So, function prototype is where it doesn't have this body, which is the actual code that is supposed to do. So, it does work as well. If you run here, but it will tell you that uh I'm sure I wanted to see this.
It will tell you that warning, implicit declaration of function add. It's a warning.
So, it's not the recommended way of just doing it. So, you need to give the function prototype. If I do this and run this, you'll find out that that warning is gone, something like that.
So, it works, but that's not the best way to do it. And I do not encourage you to what? To do it that way. Make sure that you give the function prototype. That That's how you use to these function prototypes. Right? So, that you would also understand it maybe when it comes to the theoretical part of it, whatever.
When I'm being asked about functions, you need to understand what are functions, how do you declare functions, um whatever. And that process of declaring, that's where you have the prototype function prototype. That's where you have the function definition.
You need to to to know all those things.
Function prototype parameters, function the the parameters.
How do you pass values to a to a to a function, which which means you do it through parameters, and those parameters needs to have order, something like that. Right? If here it's int and a float there, then what you are going to do when you're passing the values, you need also to make sure that you first pass this person an integer, then followed by the double value or a float value, something like that. Depends with what you have put here. So, you need also to maintain the order. So, you need to know all those theoretical part of a what of a function, something like that. Here we just maybe mainly looking at what we are supposed to what to do. Now, let's look at um write a C program that accepts student name and marks. Then you need to display grade based on the following scale.
So, what you need to do, guys, is to accept student name and marks, and then you display grade based on the following scale.
So, we have got a again, less than zero and greater than 100 invalid. And then zero between zero and 30, that's a fail.
31 and 45, that's a what? An E.
46 to 49, that's a D. 50 to 59, that's a C. 60 to 69, that's a B.
And then greater than or equal to 70, that's an A, which is actually most of you are watching here. Cuz I know that after this live tutorial, you'll be going to be good when it comes to answer uh some of questions of this what of this nature.
Okay, so now let's look at um um the the so the the demands of the question, right? So that we do not miss anything there. So, if you look at it, we need to accept student name and marks. That's the first thing. And then we need to display grade basing on the what on that grading system that we have or basing on that scale, right? That's so.
Okay, so now let's look at uh how we can work around with this. That's so.
Okay, let me take out this function.
Let me take out this function what? Uh function prototype.
Okay. So, what I'm going to do here, I'm going to declare a variable to store student's mark. And then I'm going to create a variable to store the name of a student. Because we do not have the string data type in C programming, we are going to use character array to store the name of a what of a student.
And the format is specified that we use or that place holder, something like that, is percentage S for this. Okay, so the next thing is to accept student name and marks, right? So, let's see uh print F.
Uh we say enter name or whatever.
Enter a student name.
That's so. Then let me just put a slash N there.
And then what do I do there? I'll say scan F.
Then in here, I need to put percentage S.
And then I'll put the address operator, and then I'll just write name.
Then what do I do next?
Let me take the mark, right? So, I say print F to print to screen that enter mark. And then what do I do next after doing this?
What I will do here is to say or let me just say enter student mark. I was checking if there are any questions there, but there are no questions for now.
So, which means we are good. So, I put a slash N there. Let me remove this unnecessary space, whatever. Then what do I do after this? I'll put a scan F.
And then I'll write here because it's a integer, I will use percentage D, and then I'll put the address operator uh there.
And then I'll write mark. That's so.
So, because I'm being asked um to take student name and marks. That's so.
So, it's obvious that uh the mark is going to be used to evaluate for us to to find the grade. And then what about the name?
I'm sure we need to print that name as well to say maybe it's Ezekiel, then we print the grade A or B, something like that. That's so.
Yes. Than to just take the name there and let it sit in that in the code just like that. So, here let me just print F.
I'll just print the name followed by the grade. I'm going to show you how are we going to print that grade, right? For now, I'm just going to print uh the student name there. So, I just say name just like this. And then I'll put percentage S there.
And then I'll skip a line, something like that.
And then I'll write name there.
And then let's test and see if this part is good. So, also, guys, you need to put those comments, those single-line comments that we have put that I have demonstrated before. So, here I'm just going to say Ezekiel, and then it will ask me to enter mark, then it will print the name there. So, what is left to be printed out there is just the is just the the grade, right? Just the grade. That's so.
So, what do we do now? Let's go to the scale. The first thing is first. Let's make sure that any number which is less than zero or greater than 100 is just invalid.
Just like that. That's so. So, here what do I do here? I'll go for the if statements. That's so. This is the syntax of the if statement. We've done it before. So, here I'm going to check if mark is less than zero.
Let me put some space so that it looks nice. Then I use this pipe for or.
Um mark is greater than 100. That's so.
Just like this. And then when we do this, let's print whenever we have got this mark being entered by the user, let's just print invalid.
Just like that.
And then I'll we'll terminate. So, let's test to see if everything works fine.
Okay.
I'll type the name.
And then I'll put minus five.
Then I'll get the name and the grade is invalid. Just like that.
Da da da da.
Okay.
What else I find it it's it's good, but it's not that good, right?
Maybe I was supposed to print the grade here so that it's maybe it also looks nice, but that's not it.
If I'm going to do it, maybe let me let me just go back to the demands of the question. Display grade based on the following scale. Just like that. Okay.
So, maybe I could just print grade here as this. Maybe so that it will just match, but otherwise, no one is going to penalize you for that. Otherwise, you could just print invalid. There's no problem. I just want it to look better to show that uh maybe So, I'll get the grade as invalid, and the name is something like that. If you want also, you could even put the mark, but it's not necessary. It's not necessary. So, now let's look at this.
Now, we are able We have managed to capture this part this first part, right? So, the next thing is to to cater for the range between zero and what and 30. But if you look at it, I'm trying to save you from write all these two conditions like where you put the range if mark Now, maybe you'll be say if mark is greater than or equal to zero and less than or equal to 30, then you say F, something like that. So, you want to try to run away from that. Because now we have already eliminated the range of above 100 and less than zero. So, now we are left with the range between zero and 100. So, what if I I come here and put an else if statement just like this? So, else if just like this, and then I'll do this.
What if I just put here um maybe when mark is less than or equal to 30. What does it do, right? What it means is that whenever I put something between a zero and a 30, I'm going to get a what?
Print F.
Grade. You could just write F there.
Just like that. There's no problem. You could just write F, and that's the best thing that you can also do to uh to just save your time. But let me just write grade F. And then let me just do this.
So, let me put a number like maybe Sorry, I need to put the name first.
And then let me put a number like maybe eight there.
Then I'll get the grade what? As F. What is happening? It will check is it mark less than zero or or mark is greater than one? No, because we have put a seven. So, it will goes to check on the else if statement next. So, is it seven less than or equal to 30? Yes, then it will print that grade is F. Now, let's look at um the next grade, which is 31 to what? To 45. So, whenever someone enters a number between 31 and a 45, what does it do? We need to show that the grade is what? Is E, something like that. So, let's just put another else if statement, and then we'll just say that um mark is less than or equal to 45, something like that. What do we do?
We print if that uh the grade Then we write Was it E? I don't don't remember, but I think it's what? It's an E there. So, yes, it's an E, just like that. So, I'll run this.
Then I'll write this. Then I'll write the mark, let me put 45, and I'll get an E. If you look at it, I didn't get an F.
Why? Because it will check 45 here, it's not within this range. We skip this. We check 45 here. 45 is not less than 30.
We skip. Then we check here.
Is 45 less than or equal to 45? Yes, then we get a grade E. So, it's just the same when you put any number within this range, right? So, now let's go for 46 and a 49. So, what I can do now maybe allow me to save time. Let me Just allow me to what? To copy uh this and what? And paste. Let me Just allow me to copy and paste this cuz we are just repeating. What we just need to is to change this one to what? To 49, and then the grade is supposed to be what? It's It's supposed to be D. So, we put a what? A D as our grade. So, if you look at it here, now we are checking uh at 49 going back.
But because here the upper bound was 45. So, the range is now 46 to 49, something like that. So, the next thing is for the next grade, which is a C, 50 to 59.
Allow me again to to copy this.
It's um And then put it here, and then we put a 59 there.
So, from 40 from 50 to 59, then the grade is what? Is a C.
Then allow me to do this.
60 and 69. So, I'll put a 69 there.
And then the grade is what? The grade is uh B.
And then finally, which is greater than or equal to 70.
So, you can just put the else here.
I'm sure it will cater for that remained uh uh part, which is 70 to what? To 100.
There's no way this else is going to run whenever I put any value which is greater than 100 or maybe less than zero, whatever, any value, unless if you put a value between um between a a a a 70 and 100, something like that. So, let's run this and test if everything is okay. If you have got any challenge and you want me to explain um some of the things on this code, please do ask in the comment. I'll put a 100, then name grade A, just like that.
Then we are good to go, just like this.
So, that's how you do this question. I don't know if you have any challenge with this, but otherwise, it is also wiser to put comments there as you go, right?
So, that's all on this live stream.
Um we have managed to go through this question one up to question four.
Um maybe what you could do uh on your own self maybe is to try to have maybe more exercises, maybe try to code more and see if you are able to maybe and see if you have appreciated one or two things from this live stream.
Otherwise, that's all that I have for today. I don't know if there are questions, you could also do so in the live chat. There's no problem.
Uh I will be here maybe to respond to those questions if there are no if there are questions. But as I'm seeing on the live chat there, there are no questions which are there.
So, maybe I will do call it a day.
I'll call it a day.
Thank you for watching this live stream up to um up to this point.
Um maybe I will see you on the next live stream on other what? On other topics and on other modules. Otherwise, uh that's it uh for today.
Okay, have a great day.
Let me stop this.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











