Few modifications should do the job.
#include<stdio.h>
int main()
{
char a[50],ch;
int i,j,n=0;
printf("enter your string :\t");
gets(a);
for(i=0;a[i]!='\0';i++){
n=0; for(j=0;a[j]!='\0';j++){
if(a[i]==a[j])
n++;
}
printf(" %c : %d \n",i,n); }
}
You'll still be seeing duplicate lines as you are iterating for each characters in the string without checking for duplicates. To overcome this, you can apply logic to have a string with unique characters and that you need to use for outer loop (i).
Check following links for help regarding that-
C program to remove all repeated characters in a string - Codeforwin[
^]
Remove all duplicates from a given string - GeeksforGeeks[
^]
Hop, it helps :)