My program is to find out if in the input any char is immediate repeated.For example
input::
5
RRRRR
expected output::
4
as R repeated 4 times
but given output is 2
I have tried with 2 different program.But output seems to be same.
First tried program
#include<stdio.h>
int main()
{
    char input[51];
    int n, i, count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%c",&input[i]);
    }
    for(i=1;i<n;i++)
    {
        if(input[i]==input[i-1])
            count++;
    }
    printf("%d\n",count);
}
2nd tried Program
#include<stdio.h>
int main()
{
    char a, b;
    int n, i, count=0;
    scanf("%d",&n);
    scanf("%c",&a);
    for(i=1;i<n;i++)
    {
        scanf("%c",&b);
        if(a==b)
            count++;
        else
            a=b;
    }
    printf("%d\n",count);
}
Here n is the number of char to be entered.So can anyone help me to findout where i am going wrong?
 
    