• 2 days ago
Transcript
00:00Hello everyone. I have explained this program in a flowchart and the program is to input
00:08numbers from the keyboard and count total even numbers and total odd numbers. So one
00:13by one we are going to input the values and then we will see that how many values are
00:21what even and how many are what odd. We are going to input the numbers and then we will
00:27count that number is even or odd. So how many of them are even and how many of them are
00:33odd. This is the program. So I am going to make it on C. Let us understand how to make
00:44it in C. Let me open a new file for it. So the first thing which should come in mind
01:01and the program is to count total even numbers and total odd numbers. So the first thing
01:21which should come in mind is that how many variables should we take and this is the program
01:27of loop with if statement. So how to do this let us understand. I will use the header
01:41file first of all and inside the main method I will give the variables. So let us start
01:53giving the variables and as I as how many times the loop will carry on we don't know.
02:00So for input term I am using what n. To input the number I am using what num. To count odd
02:08numbers I will use what odn. To count even numbers I will use evn. I need one variable
02:18i to carry on the loop. I hope this much variable will be okay. So let us start the work.
02:27First of all I will give a message here that is what input term okay that I have to input
02:37that how many times the loop will carry on that is %d,&n or you can say &n so the value
02:47will be inside n. Here I will apply the loop that is what i equals to 1, i less than equal
02:57to n as the loop is going to carry on for n times okay and inside it I will write down
03:07what is scanf to input the value okay that is the number which is going to store inside
03:14what num okay. Now once the value is inside num so I will see is that number is even or
03:26odd for that I will module it by 2 and the remainder should be what 0. If it's okay then
03:35it's going to count what even okay equals to evn or you can write down evn++ like this
03:45okay and if the condition is false so it will come to the else part it means that number
03:51is what odd so we have used what odn for that variable okay like this. What I also have
04:00to do is to define the values of odn equals to 0 and evn equals to 0 okay.
04:13Now once the loop will finish here I will display total count of even numbers okay %d
04:28which is here inside evn and again one more message printf total count of odd numbers
04:46which is where it is inside odn okay and I will use here what return 0. Let us save
04:56it and click on the build path so it's giving what 0 error and 0 warning run the program
05:05let us just go for 5 elements okay so I am going to input the values that is 3 and 1
05:15and 4 and 8 and 7 so 3 of them are odd and 2 of them are even yes total count of even
05:25is what 2 total count of odd is what 3, 3, 1 and 7 are odd numbers 4 and 8 are even so
05:32it's counted correctly okay. Now quickly understand it these are the variables which I have taken
05:40and num odn and evn and i odn to count the odd numbers evn to count the even numbers
05:48initial values of its are what 00 how many times the loop will carry on for that I have
05:53used n so suppose I have input what here 3 so this loop is going to work for how many
05:59times 3 times so the value of i is 1, 1 less than 3 as the value of n is 3 so the condition
06:06is true suppose I have here if I input what 5 so it will come to this if statement 5 module
06:14by 2 obviously the remainder will be there so whatever the remainder will come equal
06:20equals to 0 so the condition is false it means that number is what odd so it will come to
06:25the else part it's going to count it that is odn++ so from 0 the value of odn will be
06:34what 1 then the loop will carry on the value of i will increment to 1 from 1 to 2, 2 less
06:42than 3 the condition is true the next value suppose I input what 4, 4 moduled by 2 so
06:51the remainder will be what 0 so 0 equal equal to 0 the condition is true so that number
06:57is what even so now it's going to count what even number the value of evn that was 0 okay
07:06now it will be what 1 so out of 2 values one is what odd another one is what even now the
07:13loop will carry on the value of increment to from 2 to what 3, 3 equals to 3 the condition
07:20is true the next value which I input suppose that is 7, 7 moduled by 2 again the remainder
07:26will be there so it will come to the else part and the value of odn which was 1 then
07:33it will be what 2 then the value of i is going to increment by 1 that is from 3 it will be
07:42what 4, 4 less than 3 the condition is false so it will come out of this for loop and it's
07:49going to display the total even numbers and the total odd numbers so I hope you all understand
07:58the program okay this is the program in the next class I will explain something else thanks

Recommended