The quality of information and knowledge you providing us is far better then any other famous utube coding channels like apni kaksha and all🌻hat's off to you
interesting solution what i did was lengthy perhaps, but this is short and more logical way of doing things. instead of checking on digit by digit you solve the problem in nice and smooth manner
what if i enter number "012340", after dividing the first 2 digit which is '01' to 10 it'll give 0 and hence it wouldn't enter while loop and print out "No" so in addition you should also check if it's first is "0" or not.
But woo ise bada ho jaye ga..and time me bhi difference aye ga....phele mene bhi wahi socha tha and then I realise his method is more accurate and fast
sir please try to use for or do while loop cuz while loop is kinda useless and only takes our time to learn . practically for loop +if else statement could act as a while loop.
Do you have any video explaining a program to check whether any alpahbets is repeated? By using the same formula, I mean without using for loops. Thanks
Can anyone tell 1)the prgrm to know what are the digits that are repeated in the given number? 2)the prgrm to know which digit repeated and how many times it is repeated in the given number?
#include int main() { int seen[10] = {0}, rec[10] = {0}; int N, rem; printf("\tenter the number : "); scanf("%d", &N); while (N > 0) { rem = N % 10; if (seen[rem] == 1) { rec[rem] = rec[rem] + 1; } else { seen[rem] = 1; } N = N / 10; } for (int i = 0; i < 10; i++) { if (rec[i] > 0) { printf(" \t%d is repeated %d times.", i, rec[i] + 1); } } return 0; }
here's the code to print how many times a digit is repeated, hope it helps. #include int main() { //create array full of zeros int seen[10]={0}, i; int N; printf("pls insert a number "); scanf("%d", &N); int rem; //while loop to count how many times a number while (N>0) { rem=N%10; seen[rem]=(seen[rem]+1); N=N/10; } for (i=0; i
I have a question: what if we change the size of the array rather than 10 which you have declared in the video what will happen if we change it to any other size , will it give the wrong output or will it work fine
Bhai , a=10; In case of x=a++; x=10 but a =11. cause of post increment of value of a. But for x=++a; we get, x=11 and a = 11.cause of pre increment of value of a.
What if I enter '1070'? In this case 0 is repeated, but if 0 is the reminder, then it won't iterate... It should exit the loop, but it does complete it's task, why?
it will iterate for sure because we are checking whether 1 is stored in arr[rem=0] or not...so there is no effect of rem being 0 in the first case but when the rem again comes out to be zero..it will come out of the loop as the value at arr[0] is already equal to 1 because of the first rem. that's why this code is able to check all the positive integera.
Another method using bruteforce instead of math: int main(void) { int array[] = {10, 20, 30, 40, 10, 10, 70, 80, 90}; int count = sizeof(array) / sizeof(array[0]); for (int i = 0; i < count-1; i++) { for (int j = i+1; j < count; j++) { if (array[i] == array[j]) { printf("%d ",array[i]); } } } return 0; } Say you've got 9 items in an array and want to compare each pair of items: start with the first one, and compare it to each of the other 8 items in the array. That's 8 comparisons so far. Then move to the second one. No need to compare it to the first item, you already did that, so compare to each of the remaining 7 items. Repeat this process and you'll end up with 8+7+6+5+4+3+2+1=36 comparisons. And that's just what the code above does
I also thought 💭 , if given no is like 35385 or any other then what logic we have to add ? Many of your subscribers also want it's solutions as you take attention to comments . So I kindly request you to give ethier a small reply from you or a presentation .
#include int main() { int num,rem,i,j,k,num2,count=0; printf("enter the number :"); scanf("%d",&num); printf("enter the number which you want to check in given digit"); scanf("%d",&num2); while(num!=0) { rem=num%10; //it will give us remender means last digit of a line if(num2==rem) count++; num=num/10; } printf("_______________ "); printf("here %d occure in %d time in digit",num2,count); return 0; }
When I am using a 11 digit number such as 12345678901 even after using unsigned long long int data type it is messing up the result. What can be the reason for this?
in previous video you said that ;;;;;if we take a[10] it will take only 10 numbers ::::but in the above video i took seen[4] but entered value is 6 digit program executes and why should we tak that seen[10]={0}
aww, nice solution. Im so stupid, I straight up read the number as a string of characters and looped through the string checking if we have repeated chars lmao
Hello Sir, I solved this problem before watching your solution and this is what I came up with. #include int main() { int num, nums[5], dup = 0; //Input stage printf("Please enter a five digit number: "); scanf("%d", &num); // Processing stage int temp = num; //Transferring each digit of num to the array nums for(int counter = 0; counter < 5; ++counter) { nums[counter] = temp % 10; temp /= 10; } //The algorithm for(int counter = 0; counter < 5; ++counter){ for(int counter1 = (counter + 1); counter1 < (5 - counter); ++counter1) if(nums[counter] == nums[counter1]){ dup = 1; break; } if(dup) break; } //Output stage if(dup) printf("%d has a repeated number", num); else printf("%d does not have a reapeated number in it", num); return 0; } BTW I your program is better than myn because of obvious reasons:)
@@yashwanthrajlakumarapu9738 #include int main() { int num,rem,i,j,k,num2,count=0; printf("enter the number :"); scanf("%d",&num); printf("enter the number which you want to check in given digit"); scanf("%d",&num2); while(num!=0) { rem=num%10; //it will give us remender means last digit of a line if(num2==rem) count++; num=num/10; } printf("_______________ "); printf("here %d occure in %d time in digit",num2,count); return 0; }
We can manipulate this code and can find out:- 1. Which number is repeated how many times? 2. We can even used it for alphabets. 3. We can build a program to find out repeated alphanumeric names.
I also solved it but mine is kinda weak since I needed to know how many digits is the input and then take it one by one and do a comparison but yours is much more convenient and smarter , I feel dumb
#include int main() { int num,rem,i,j,k,num2,count=0; printf("enter the number :"); scanf("%d",&num); printf("enter the number which you want to check in given digit"); scanf("%d",&num2); while(num!=0) { rem=num%10; //it will give us remender means last digit of a line if(num2==rem) count++; num=num/10; } printf("_______________ "); printf("here %d occure in %d time in digit",num2,count); return 0; }
At first I tried it didn't work and I modified the part 3 section and after that still not working, I switched it back to the original as below: If(N>0) printf("Yes"); else printf("No"); it works. but then I thought of another method like this: if (N==0) puts("No"); else puts("Yes"); which is much simpler and it works too. The reason why if u key in 000 or 001 and so anything with 0 in the beginning followed by a value, compiler will ignore the zero and read it as 1 in case of 01, 001, try putting 0011, and it will be understood as 11 and the output will be "YES MACHA!" this is a repeated number
Yes correct! Even I experienced it! int main() { int num,rem; int a[10]= {0}; int count = 0; char c;
printf("Enter the number: "); scanf("%d",&num); for( num; num > 0; num/=10) { rem = num%10; if(a[rem] == 0) a[rem]++; else a[rem]++; } for(int i = 0; i=2) { printf("%d is repeated %d times ", i,a[i]); count++;} } if(count == 0) printf("NO digits are repeated "); return 0; } I wrote the above code to check which digit is repeated, for numbers like 000011 it does take into consideration the 0 digit! Do you know the solution?
what's happen if i input the number 1206? you take the seen array in which all the entries are zero, so in the second comparison of digits the loop will break but zero is not repeating in number. then what should we do?
@@ttobg % (modulus) operator returned the remainder value to the variable means I am confused if it is so, variable rem will get value 0.. 2 here is dividend not a remainder..🤔
@@learnwiththapa2886 remember modulus operator gives the last digit of a number and if the number is itself a single digit then it will return that particular single digit.
Thank you sir it was a great video.But when i enter any large number in my program, then it does not work properly. I entered a number which has more than 10 digits. Is it because of that?
#include int main() { int seen[10] = {0}, rec[10] = {0}; int N, rem; printf("\tenter the number : "); scanf("%d", &N); while (N > 0) { rem = N % 10; if (seen[rem] == 1) { rec[rem] = rec[rem] + 1; } else { seen[rem] = 1; } N = N / 10; } for (int i = 0; i < 10; i++) { if (rec[i] > 0) { printf(" \t%d is repeated %d times.", i, rec[i] + 1); } } return 0; }
You are great Sir. I follow the lectures of you. That are very easy after watching. Thanks a lot Sir. A big salute to you.
hey,neso academy team can you plss.. upload videos on the array operations such as : insertion,deletion,search etc.
The quality of information and knowledge you providing us is far better then any other famous utube coding channels like apni kaksha and all🌻hat's off to you
I'm amazed to see such an intuitive explanation!!!
interesting solution what i did was lengthy perhaps, but this is short and more logical way of doing things. instead of checking on digit by digit you solve the problem in nice and smooth manner
I have made that program but using another logic. But sir your logic is comparatively more short and easier..... 👍👍👍
what if i enter number "012340", after dividing the first 2 digit which is '01' to 10 it'll give 0 and hence it wouldn't enter while loop and print out "No" so in addition you should also check if it's first is "0" or not.
>= hona chaiye tha
If u do so, 0 preceding actual number is converted to octal equivalent in c and it proceeds
@@Doraemon-cq8jhinfinite loop ho jaayega
0 is quotient and we need the remainder which we get 1
I am becoming fan of neso academy your lectures were awesome
wow sir just wow
I want to say, this is the best content
the way you explain the things, it's just excellent.
I got another idea using 2 array of string character. Then compare using nested loop.
A1 vs B1, A1 vs B2..
A2 vs B1, A2 vs B2..
But woo ise bada ho jaye ga..and time me bhi difference aye ga....phele mene bhi wahi socha tha and then I realise his method is more accurate and fast
this is an innovative way of doing it . generally people apply nested loops for solving
great logic ,when i tried on my own it took 3 for loops,but with this one while loop is enough
You can avoid the part 3
while (num>0){
N = num % 10;
if (arr[N] == 1){
printf("Yes!");
}
arr[N] = 1;
num = num / 10;
}
like this. Thank you for your video series. I learned lot of things ❤❤
Yes but it is for user satisfaction. That according to his/her input program displays correct information
Your videos are mesmerizing sir ! Thank you so much for uploading these....🤗
function hasDuplicates(num) {
var digits = [];
while(num > 0) {
digits.push(num % 10);
num = Math.floor(num / 10);
}
digits.sort();
for(var i = 0; i < digits.length - 1; i++) {
if(digits[i] == digits[i+1])
return true;
}
return false;
}
The best Teacher, I learn a lot from you
you are doing great job sir.......thankyou sir....the way you teach is fabulus......thankyou so much sir
Can you make more videos on array and string
sir please try to use for or do while loop cuz while loop is kinda useless and only takes our time to learn . practically for loop +if else statement could act as a while loop.
Please make a playlist on algorithms....nd try to cover all topics with prerequisites
Its amazing to learn ,such a good explaination,thanks a lot.
Do you have any video explaining a program to check whether any alpahbets is repeated? By using the same formula, I mean without using for loops. Thanks
Can anyone tell
1)the prgrm to know what are the digits that are repeated in the given number?
2)the prgrm to know which digit repeated and how many times it is repeated in the given number?
#include
int main()
{
int seen[10] = {0}, rec[10] = {0};
int N, rem;
printf("\tenter the number : ");
scanf("%d", &N);
while (N > 0)
{
rem = N % 10;
if (seen[rem] == 1)
{
rec[rem] = rec[rem] + 1;
}
else
{
seen[rem] = 1;
}
N = N / 10;
}
for (int i = 0; i < 10; i++)
{
if (rec[i] > 0)
{
printf("
\t%d is repeated %d times.", i, rec[i] + 1);
}
}
return 0;
}
here's the code to print how many times a digit is repeated, hope it helps.
#include
int main()
{
//create array full of zeros
int seen[10]={0}, i;
int N;
printf("pls insert a number
");
scanf("%d", &N);
int rem;
//while loop to count how many times a number
while (N>0)
{
rem=N%10;
seen[rem]=(seen[rem]+1);
N=N/10;
}
for (i=0; i
Have u compiled it ?
Does it produced the crct result?
we need data structure and algorithm from you.
kar diya hai lavde
@@Randibaaj_sala swag😂😂
hi guys are you alive in this covid period 😂😂🤣😂😂😅☺😅🤣😂🤣😅🤣😂😅🤣😂🤣😅
@@adithya3890 tmhre amma ki jai.
Great teacher
if you give the n = 00;
the output gonna be no and thats incorrect
I have a question: what if we change the size of the array rather than 10 which you have declared in the video what will happen if we change it to any other size , will it give the wrong output or will it work fine
Your teaching like god level
Instead of assigning the value 1 shouldn't we assign the remainder in the array and break if the value is not equal to 0?
Of course we can. I am also thinking about it.
thank you for detailed explanation.
While( n>0)
Rem=n%10
If( rem==rem)
Print("number is twice display")
N=n/10
}
Is it correct
What will be the output if value is 50
At last after if condition value of N =5 , which is greater than 0 so output is yes..but there is no repetition
it will divide 5 by 10 and give 0
Thanks Sir for this video... it's really helpful...
very good example thank you for the videos
excellent teaching Thank for helping sir!
please upload more questions its highly helpful
Pw c programming array waha vi kraye h bhot question
but sir only yes will be coded after dialing any number repeated or nonrepeated 😢😢
What if when number is repeated more than once ...how we can calculate its length
great job
Sir ......if a=10;
x=a++;
What is the value of x here ??
since it is a post fix expression ,value of x =10, as the value is assigned before increment is done on ' a '.
@@alkapathak59 thanks
a=11
@@mhmdfathi6780 a yeah, but x=10
Bhai , a=10;
In case of x=a++;
x=10 but a =11. cause of post increment of value of a.
But for x=++a;
we get, x=11 and a = 11.cause of pre increment of value of a.
beautiful solution sir.
If the number input is 1000
It won't be >0
amazing one sir
great idea sir
What if I enter '1070'? In this case 0 is repeated, but if 0 is the reminder, then it won't iterate... It should exit the loop, but it does complete it's task, why?
it will iterate for sure because we are checking whether 1 is stored in arr[rem=0] or not...so there is no effect of rem being 0 in the first case but when the rem again comes out to be zero..it will come out of the loop as the value at arr[0] is already equal to 1 because of the first rem.
that's why this code is able to check all the positive integera.
new approach to this Question..😄
Thank You Sir
Sir i am not able to design algorithms of programs, like the program explained in this video. What should I do?
refer geeksforgeeks
yeah even I did made a program to get this output but my code and way of thinking was not like this. I don't know what to do
Another method using bruteforce instead of math:
int main(void)
{
int array[] = {10, 20, 30, 40, 10, 10, 70, 80, 90};
int count = sizeof(array) / sizeof(array[0]);
for (int i = 0; i < count-1; i++)
{
for (int j = i+1; j < count; j++)
{
if (array[i] == array[j])
{
printf("%d
",array[i]);
}
}
}
return 0;
}
Say you've got 9 items in an array and want to compare each pair of items: start with the first one, and compare it to each of the other 8 items in the array. That's 8 comparisons so far. Then move to the second one. No need to compare it to the first item, you already did that, so compare to each of the remaining 7 items. Repeat this process and you'll end up with 8+7+6+5+4+3+2+1=36 comparisons. And that's just what the code above does
This is what came to me at first too..but the time complexity is way worse.
not applicable if we enter such number like 0091 for instance. Answer would be "No" despite the repeating zeroes
I also thought 💭 , if given no is like 35385 or any other then what logic we have to add ? Many of your subscribers also want it's solutions as you take attention to comments . So I kindly request you to give ethier a small reply from you or a presentation .
then applay for loop in for loop with the same logic use nested if situation you will get the output how many time a digit has been repeated
#include
int main()
{
int num,rem,i,j,k,num2,count=0;
printf("enter the number :");
scanf("%d",&num);
printf("enter the number which you want to check in given digit");
scanf("%d",&num2);
while(num!=0)
{
rem=num%10; //it will give us remender means last digit of a line
if(num2==rem)
count++;
num=num/10;
}
printf("_______________
");
printf("here %d occure in %d time in digit",num2,count);
return 0;
}
@@vivektripathi9863 how bro i am not getting that
@@pankajkesharwani8088 what error you are facing bro ?
//An alternate method
#include
int main()
{
int a[5],i,j,count=0;
printf("Enter 5 numbers");
for(i=0;i
wow what a solution sir ji
ma man jaspr!
Sir please complete power systems please .....i eagerly waiting to have grip on it
Thank you sir .🙂
When I am using a 11 digit number such as 12345678901 even after using unsigned long long int data type it is messing up the result. What can be the reason for this?
You are best sir! 😊
Anybody tell me how the rem is 2 at 4:56
Please help me,my English is bad,where does the two at 4:41 come from? Can anyone help me, I know this question 😂is kind of stupid 😢
All right, I‘m good now,thanks
In may task having the same problem but i must count every number and print it and how many times it's been repeated
in previous video you said that ;;;;;if we take a[10] it will take only 10 numbers ::::but in the above video i took seen[4] but
entered value is 6 digit program executes and why should we tak that seen[10]={0}
very nice ans smart program thanks
Why we using the condition in if statement as n>0
In line 7, if i write : scanf("%d ", &N); , then i must type 2 times the number, the program will run. I don't know why ?
this is very smart!
amazing!
Really gud video.... Keep doing this..
yes,its true
Thank you!
Thank you neso
Good Logic sir
Best explaination ever.
How to know when to use loops 😢. And when to use n%10 like that thing
Thanks
Sir if entered digit is 00 this will not work
aww, nice solution. Im so stupid, I straight up read the number as a string of characters and looped through the string checking if we have repeated chars lmao
Hello Sir, I solved this problem before watching your solution and this is what I came up with.
#include
int main() {
int num, nums[5], dup = 0;
//Input stage
printf("Please enter a five digit number: ");
scanf("%d", &num);
// Processing stage
int temp = num;
//Transferring each digit of num to the array nums
for(int counter = 0; counter < 5; ++counter) {
nums[counter] = temp % 10;
temp /= 10;
}
//The algorithm
for(int counter = 0; counter < 5; ++counter){
for(int counter1 = (counter + 1); counter1 < (5 - counter); ++counter1)
if(nums[counter] == nums[counter1]){
dup = 1;
break;
}
if(dup)
break;
}
//Output stage
if(dup)
printf("%d has a repeated number", num);
else
printf("%d does not have a reapeated number in it", num);
return 0;
}
BTW I your program is better than myn because of obvious reasons:)
Great. Thanks 😌
sir,this program doesnt give the proper output,if n=non repeated digits,wht op im getting is yes only
me 2
@@yashwanthrajlakumarapu9738 #include
int main()
{
int num,rem,i,j,k,num2,count=0;
printf("enter the number :");
scanf("%d",&num);
printf("enter the number which you want to check in given digit");
scanf("%d",&num2);
while(num!=0)
{
rem=num%10; //it will give us remender means last digit of a line
if(num2==rem)
count++;
num=num/10;
}
printf("_______________
");
printf("here %d occure in %d time in digit",num2,count);
return 0;
}
Sir how can it be compiler u didnt declare rem
We can manipulate this code and can find out:-
1. Which number is repeated how many times?
2. We can even used it for alphabets.
3. We can build a program to find out repeated alphanumeric names.
Excellent 👍👍👍👍
I also solved it but mine is kinda weak since I needed to know how many digits is the input and then take it one by one and do a comparison but yours is much more convenient and smarter , I feel dumb
#include
int main()
{
int num,rem,i,j,k,num2,count=0;
printf("enter the number :");
scanf("%d",&num);
printf("enter the number which you want to check in given digit");
scanf("%d",&num2);
while(num!=0)
{
rem=num%10; //it will give us remender means last digit of a line
if(num2==rem)
count++;
num=num/10;
}
printf("_______________
");
printf("here %d occure in %d time in digit",num2,count);
return 0;
}
How do you explain that below program?
#include
#include
int main(){
char s[1000];
int x,i,count[10]={0},a=0;
gets(s);
for(i=0;i
At first I tried it didn't work and I modified the part 3 section and after that still not working, I switched it back to the original as below:
If(N>0)
printf("Yes");
else
printf("No");
it works.
but then I thought of another method like this:
if (N==0)
puts("No");
else
puts("Yes");
which is much simpler and it works too.
The reason why if u key in 000 or 001 and so anything with 0 in the beginning followed by a value, compiler will ignore the zero and read it as 1 in case of 01, 001, try putting 0011, and it will be understood as 11 and the output will be "YES MACHA!" this is a repeated number
Yes correct!
Even I experienced it!
int main()
{
int num,rem;
int a[10]= {0};
int count = 0;
char c;
printf("Enter the number: ");
scanf("%d",&num);
for( num; num > 0; num/=10)
{
rem = num%10;
if(a[rem] == 0)
a[rem]++;
else
a[rem]++;
}
for(int i = 0; i=2)
{ printf("%d is repeated %d times
", i,a[i]);
count++;}
}
if(count == 0)
printf("NO digits are repeated
");
return 0;
}
I wrote the above code to check which digit is repeated, for numbers like 000011 it does take into consideration the 0 digit!
Do you know the solution?
what's happen if i input the number 1206?
you take the seen array in which all the entries are zero, so in the second comparison of digits the loop will break but zero is not repeating in number.
then what should we do?
he is checking for 1 and not whether the value is same
Ohh! ya ya ya
Thank you
Sir, in Part 2 explaination, 2%10 will give 0 as a remainder which will be returned to rem variable. or am I wrong, please help me with this.
2 divided by 10 would be 0, and you are left with 2
@@ttobg % (modulus) operator returned the remainder value to the variable means I am confused if it is so, variable rem will get value 0.. 2 here is dividend not a remainder..🤔
@@learnwiththapa2886 remember modulus operator gives the last digit of a number and if the number is itself a single digit then it will return that particular single digit.
Thank you sir it was a great video.But when i enter any large number in my program, then it does not work properly. I entered a number which has more than 10 digits. Is it because of that?
int has a specific size of byte upto which it can store a value. For long digit numbers, try long int
Can we check which digits are repeated and how many times?
#include
int main()
{
int seen[10] = {0}, rec[10] = {0};
int N, rem;
printf("\tenter the number : ");
scanf("%d", &N);
while (N > 0)
{
rem = N % 10;
if (seen[rem] == 1)
{
rec[rem] = rec[rem] + 1;
}
else
{
seen[rem] = 1;
}
N = N / 10;
}
for (int i = 0; i < 10; i++)
{
if (rec[i] > 0)
{
printf("
\t%d is repeated %d times.", i, rec[i] + 1);
}
}
return 0;
}
thank you so much sir
Sir if we put there the no 1204 then sir it will break because of 0 then sir this is wrong
With all due respect to math wizards out there, how is 2%10 has a remainder 2? (video time 4:55)
sir will this code work for 9006
Sir make network theory videos
when we enter 00 then it will show no....and that is wrong
in this video we used the bloom filter and a kind of hash table isn't ?
what is the level of this problem?
Sir neso acadamy will upload network theory classes or not sir please reply sir
We are prolonged waiting for NT classes
Thank0--you