C program to print number of times a digit has been Repeated
Input:First line contains 'N'
Second line of input contains N number of integers.
Output:
Number of times a digit has been repeated.
Example:
Input:
6
1 1 7 7 7 9 9 9
Output:
2 3 3
Explanation:
1 is repeated for 2 times 7 is repeated for 3 times and 9 is repeated for 3 times.
SOURCE CODE:
/*To find number of times a digit is repeated*/
#include<stdio.h>
int main()
{
int a[50],n,i,j,c=0,r=0,b[10]={0}, k;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0,k=0;i<n;i=j,k++)
{
c=0;
for(j=i;;j++)
{
if(a[i]==a[j])
{
c++;
}
else
{
b[k]=c;
break;
}
}
}
k=0;
while(b[k]!=0)
{
printf("%d ",b[k]);
k++;
}
return 0;
}
great informationCISCO Meraki Switches Firewall
ReplyDeletegreat your information is very helpful .
ReplyDeleteDvivek