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
8 odpowiedzi
+ 7
Hello ramkrushna karnikanti
Please share.your code so that we can see the error.
+ 1
Ok 😊
+ 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
+ 1
ramkrushna karnikanti
Tbh, I don't see a pattern in 1235656. So I have no idea.
+ 1
Thank you so much
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;
}
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
0
One more question is how to print pattern big alphabet c in star pattern