Functions (Solved Question 1)
Вставка
- Опубліковано 6 жов 2024
- C Programming & Data Structures: Functions (Solved Question 1)
Topics discussed:
1) Solution of GATE-2014 (CSE) problem on Functions in C.
2) Homework problem on Functions in C.
C Programming Lectures: goo.gl/7Eh2SS
Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
Contribute: www.nesoacademy...
Memberships: bit.ly/2U7YSPI
Books: www.nesoacademy...
Website ► www.nesoacademy...
Forum ► forum.nesoacade...
Facebook ► goo.gl/Nt0PmB
Twitter ► / nesoacademy
Music:
Axol x Alex Skrindo - You [NCS Release]
#CProgrammingByNeso #CProgramming #CFunctions
Starting by incrementing from count(2)
Count(2): 110110011__ itr0
Count(3): 001101100__itr1
Count(4): 000011011__itr2
Count(5): 000000110__itr3
Count(6): 000000001__itr4
Count(7): 000000000__itr5
After count(7) we get out of the loop.
Right!
Right !!!
Absolutely Perfect!
The answer is 7?
@@cherryayethihan yah
I am too late to watch this series but really this is best series for learning c and data structures....
same
it's never too late....BETTER LATE THAN NEVER.....starting to learn and progressing till this video is a great step...keep going...keep growing
Yes bro... I want this video playlist to come in first after search.... S
@@foodmonk2292 That's really an inspirational line bro
@@foodmonk2292 True!
lot of years im search a good tutorial for c but now i find a gold tutorial...super presentation and simple and quality examples
the answer is 7, as the count starts from 2 and the loop terminates after 5 iteration so 5+2=7.
But my answer is 6
@@rimpinag6346 i have already explained
@@IntradayWithShahid ok okk understand
👍 I am little bit confused
@@IntradayWithShahid 🤣🤣🤣
Smjh ni aya
Here num is 435 (110110011) and count=2, if we shift right the number like
001101100(3) ,here 3 after count (2 )give that, for understanding
Similarly,
000011011(4)
000000110(5)
000000001(6)
000000000(7)
After counting it gives 7 if we count after 2 and another simple way is 2+5=7.
I have a little bit different approach. As it is a right shift that also we have to do 2 times per iteration so as discussed in previous lectures in right shift we divide no. By
2^(no. Of bits to right shift)
so here no. Of bits to shift is 2 so we will divide by 2^2 i.e. by 4. So when we count the iteration along with dividing no. The loop will terminated at 5th iteration as at 5th iteration the value i.e. the no. Will be 0 after dividing. So the final answer is 5+2 = 7. i.e. count =7
Value of count is 7.And the loop terminates after 5 iterations. Initially the value of count is 2 and after 5 iterations it will be 5+2=7.
For the loop to terminate :-
(435/4^x) 4^x>435 => x=5.
And since count is initiated with 2 , hence final o/p - 2+5 = 7.
Someone explain this pls?
let me explain u
we take the value the give num and divide it by 2*2^n (first 2 is no. of swifting we are doing ,then net 2 is poissible output that is 0and1 power x which is iteration) smaller then 1 because we need to make the binary number zero which is less then 1@@debjyotisarkar9578
Bro explain it pls
435= 110110011 c=2
//right shift 2
num=001101100 c=3
num= 000011011 c=4
num=000000110 c=5
num=000000001 c=6
num=000000000 c=7
Ans= 7
I got 7 for the count: 5 loop iterations for the shifts plus the initial 2 of count.
Count = 2 (Initial Value)
Count = 7 (Final Value)
Answer is Count = 7
1. 435/4 = 108; count=3
2. 108/4 = 27; count=4
3. 27/4 = 6; count=5
4. 6/4 = 0; count=6 1/4=0 count=7 (final answer)
Why did you divide by 4?
He should be a private tutor for c he deserves even more i prefer to watch his videos rather than other hindi programming videos
It is really useful for my gate preparation thank you sir
The Answer is 7
Thanks sir for your effort
7
is the value returned by the function
When count = 7 num contains 0 value.So the condition became false and we came outside of the loop and return the value of count which is 7.So 7 is the right ans.
I think it can be done with the shortcut formula you told in previous videos i.e. in right shift we divide the given number by 2^number
so i ain't the only one who did it that way!
Thanks a lot to neso academy,
For giving eacha and every concept clear as water
7. Because, now every time >> shift num by 2 bits,so num becomes num/4 each time, and 5 time loop, will make count =2+5=7.
now likes are also 7
@@adityaband6919 i broke it dear now it is 8 ....hahahah
but what if the count value was intialised with 0. ?
4
5
Ans in 7 sir bcz 435 in binary 110110011 and given that shifting by 2 when count is 2 the while loop will terminate after 5th iteration (the value of num is then num =000000000) and the Value of count returns is 5+2=7 ans..
THank
you so much
could u plz tell me how it will be 7 again?
You are very good teacher
The value returned by func(435) is 7. (At Iter 5 we got num=0, so 5+2=7)
count = 7.
The answer is 7. Thanks sir for your wonderful explanation.
Thx Neso Academy
Such a great Question as usual
The answer is 7
loved and enjoyed a lot, eagerly waiting for the next one and much excited for data structure lectures
Excuse me I have a doubt about 1question that num>>=1...in this why we use =operator .... it is left shift right ..then why we use =operator.
@@saisumanth2289 thank u bro,now i am realised that it is a compound assignment. thank u for ur replied message.
the value returned by func(435) is 7
Thank you for this series. It really helped me a lot.
Answer is 7.
@@sharvilsopal416 ya thanks
Ans is 7.
#include
int fun(int a){
int count=2;
while(a){
count++;
a>>=2;
}
return count;
}
int main(){
int a;
a=435;
fun(a);
printf("the value of a: %d
",fun(a));
return 0;
}
The variable count will be iterated five times, so the final value of count is 7. Best content ever!!!!
Instead of doing it BIT by BIT, We can just use this this rule, We know that when we right shift a number by any number, Say 435>>1 = 217, which we can calculate by 435/2^1, By doing it again and again in calculator until it reaches 0, we can calculate the number of iterations to make that value to 0, we can find the answer I guess ?. Correct me If I am wrong peace ✌️.
7--hmwrk answer
Hello sir ia am a starter of diploma in engineering college and i am felling greate to learn here
Bither way the answer is 7.
The answer to the homework is 7. But how to remember the bit representation of such a large number like 435. Do the question contains the bitwise representation of the given number?
7 in answer bez we shift count 5 times so 2+5 = 7.
SIR when you will upload the lecturers on datastructures.
Sir the you provided here is extremely beautiful in every way and can you please provide c++ oops concept
There will be 5 iteration in this loop. Th value of Count will become 2+5 = 7.
The answer is 8 because after integer to binary conversation we will get 11 digits number, So in 5 iterations it will remove 10 digits from no. Then 1 digit will remain for that it will iterate one more time then count could be 6 since count start from 2 so, the answer will 8.
a very good you tube channel to learn c programming.
The value returned by func(435) is 7 as count value is 7
Quick question on the first task, how is the count = 9 instead of 10, when it's being incremented before the shift operation?
while(num)
{
count++;
num>>= 2;
}
ah I did this alone. Having a civil engineering background I think Ive got so far. Thank you Neso Academy.
435/2² =435/4 = 108 itr 1
Same as it's goes for 5 times untill it reached 0
The count strats from 2
So the final ans is
5+2=7
how is the loop argument >> while(num) means while num is not equal to zero?
As regarding condition of while loop we take them as true or false and all numbers other than zero are considered as true and 0 is considered as false...
In 5th iteration num become 0 and the function returns the count value 7 so the op is 7
wouldn´t be better to write.....while(num ¡=0) instead of just while(num)??....thank you for your reply
Sir your videos are tha best plzz upload more
after count=7,while loop condition becomes false
num>>1 is equivalent to num/2
num>>2 is equivalent to num/4 (as homewok problem)
num>>3 is equivalent to num/6
So we kind of dividing 435 five times until num reach to 0, so the total iteration is 5, and in each iteration we increment the value of count starting from 2:
Iteration 1
count = 3
num = 108 (435/4, truncating decimals because num is of type int not float or double)
Iteration 2
count = 4
num = 27 (108/4)
Iteration 3
count = 5
num = 6 (27/4, truncating decimals because num is of type int not float or double)
Iteration 4
count = 6 (6/4, truncating decimals because num is of type int not float or double)
num = 1 (1/4, truncating decimals because num is of type int not float or double)
Iteration 5 (last iteration)
count = 7 (our answer)
num = 0 (0/0, so while condition return false).
Code: [Debug to understand!]
int main(void)
{
int count = 2, num = 435;
while(num)
{
count++, num>>=2;
printf("%d
",count);
printf("%d
", num);
}
printf("%d
",count); // 7
return 0;
}
Thanks bro a lot @Acces Denied
Value returned by func(435)=7
7 is the answer.
Thanks Sir
thanks a lot sir for your video lectures they are really helpfull to us thankyou very much sir
435>>=2 COUNT IS 7.
Thank you sir.
7 will be the answer. God, I am getting correct answers. So, enough for today going to sleep and have a good dream.
For left shift multiplication and for right shift division
The answer for the second case would be 5 (iterations) if I am not mistaken.
In the fifth iteration num becomes all zeros so count is 7
num / 2 power 1 .since shify by 1..
7
the ans is 7 iterations if count is 2 as it right shifted by 2
Ans : 5
The answer comes To be 7. Is it right?
C(2):110110011
C(3):001101100
C(4):000011011
C(5):000000110
C(6):000000001
C(7):000000000
Return value will be 7
We hitted the like button....and subscribed also ......but ur not solving anyone's doubt......please solve ours doubt...I request u sir.. why we use =operator in num>>=1...
sir made a videos on c++ i really like your's c videos
Count=2+5;
Count=7;
The func(435)=7;after 7th count loop can't be terminated...
Anything is wrong in my question.if you won't reply me then what is the need of doing sessions .... it's not cleared for me .... please help me sir🙏🙏🙏🙏.... Why we use=operator in num>>=1.
num>>=1 means num = num>>1
this program counted 2bits then running count value 5 and initial value 2 . then finally output is 2+5= 7 .
after count(6), value returned is 4
in iteration 5 the num became 0 and return count will be 7
Absolutely=7
Answer 1st iteration 00110110
2nd iteration 000011011
3rd iteration 000000110
4th iteration 000000001
4th iteration 000000000
Finally count -7❤
What is the need of usig = operator in num>>=1.
How binary number is shifting? I didn't get
Answer is 7
7 is answer of 2 nd eg
your way of explanation is correct, but small correction i.e 435=110111101
No, 110111101=>(256+128+32+16+8+4+1)=445....
Thank u
1|10|11|00|11 , count =2+5=7
Could you please help me in that:-
#include
void fun (int a)
{
if(a>0)
{
fun(--a);
printf("%d",a);
fun (--a);
}
}
int main()
{
int i=3;
fun (i);
return 0;
}
where it is written that num isn't equal to zero
nice explaination sir
answer is 7
thanks for explaining
7
There there will be 5 iterations until while loop turns false.
sir please upload next unit lecture please ie array
for hw, divide by 4,So answer become 7
This question is all about conversion
Is it 7 for homework q ?
yoo bruh
Please sir data structure pe or video upload kro....ab bas aap hi last hope ho mere liye...nd thanks for this video
And one thing I don't understand are ">>" and ">>=" same? It would have been the same with out "=" also, then why use "=" after ">>" ??
Without the "=" I could solve it, but it kept me thinking 🤔
">>" will only shift bit it won't reflect in actual number , ">>=" this is equal to number = number >> 1;
Oh... I see 🤔
Thanks..
Please reply anything sir....when we use num>>=1 it shows error....so ...I think num>>1 is correct...,..if you won't answer for these question these doubt is always with me and it will never clarifies.... please reply soon.... It will helpful for every student of u sir....I am the begginer for this programming .. I am basically a bio student.... please help me sir..
Num>>=1 is equal to num=num>>1
@@B-Aparnasai thank you...now I realized that it is the assignment operator.
how did we understand we have to get it out of while loop when number is 0, there is no if condition
0 means false , the compiles assumes it even though its not given.
is this bitwise operator problem?
the final count =7 bcz after 5 iteration loop terminate.
How it will strike that we have to first convert it into binary plzz answer anyone
Previous lectures se
@Rohan Rathour ok
@Rohan Rathour lecture no. 43 under loops section 1st question
Where he changes first time decimal to binary for right shift operator.
Is it a aptitude base question in gate or in some spacial branch paper?
Please someone tell me this
Not aptitude base. Its for C programming, branch: Computer Science.
Homework answer.... 7