0

Hi friends I want to print 1235656 repeated number with the help of nested for loop I tried but some errors in programplease hel

1st May 2020, 6:37 PM
ramkrushna karnikanti
ramkrushna karnikanti - avatar
8 ответов
+ 7
Hello ramkrushna karnikanti Please share.your code so that we can see the error.
1st May 2020, 6:39 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Ok 😊
2nd May 2020, 2:27 AM
ramkrushna karnikanti
ramkrushna karnikanti - avatar
+ 1
#include <stdio.h> #include <stdlib.h> int main() { int n,arr[10]; printf("Enter input :"); scanf("%d",&n); for (int i=0;i<10;i++) { arr[i]=0; } while(n!=0) { int r=n%10; n=n/10; arr[r]=arr[r]+1; } for(int i=0;i<10;i++) { if(arr[i]>1) { printf("\n%d is repeated %d times ",i,arr[i]); } } return 0; } Please tell me how to solve this problem with the help of nested for loop with out using array ,,above program is correct
2nd May 2020, 4:37 AM
ramkrushna karnikanti
ramkrushna karnikanti - avatar
+ 1
ramkrushna karnikanti Tbh, I don't see a pattern in 1235656. So I have no idea.
4th May 2020, 9:50 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you so much
5th May 2020, 2:08 AM
ramkrushna karnikanti
ramkrushna karnikanti - avatar
0
// something like this, maybe: #include <math.h> #include <stdio.h> int main() { int n, d, i, j, c, x; printf("Enter input: "); scanf("%d",&n); printf("%d",n); // only needed in code playground context if (n<0) n = -n; d = (int) log10(n); for (i=0; i<10; ++i) { for (c=0, j=0; j<=d; ++j) { x = (int) n/pow(10,d-j); if (i==(int) x%10) ++c; } if (1<c) printf("\n%d is repeated %d times",i,c); } return 0; }
4th May 2020, 11:12 PM
visph
visph - avatar
0
// optimized version ;P #include <math.h> #include <stdio.h> int main() { int n, d, i, c, p; printf("Enter input: "); scanf("%d",&n); printf("%d",n); // only needed in code playground context if (n<0) n = -n; d = (int) pow(10,(int) log10(n)); for (i=0; i<10; ++i) { for (p=d, c=0; 0<p; p/=10) if (i==(n/p)%10) ++c; if (1<c) printf("\n%d is repeated %d times",i,c); } return 0; } // https://code.sololearn.com/cU9PFmwDkKgS/#c
4th May 2020, 11:33 PM
visph
visph - avatar
0
One more question is how to print pattern big alphabet c in star pattern
5th May 2020, 2:09 AM
ramkrushna karnikanti
ramkrushna karnikanti - avatar