Wednesday 7 June 2017

Secure the given valid id's by making 1st 9 digit as *.

Secure the given valid id's by making 1st 9 digit as *.
valid id is identified by following condition.
1) Even places of a number sum is greater than the odd places sum.
2)It's consists of 13 digit

#include<stdio.h>
#include<string.h>
int main()
{
 int count=0,odd=0,even=0,i,start=-1,end=-1;

 char a[100];
 int j=0;
 gets(a);
 printf("%s\n",a);
  for(i=0;i<strlen(a);i++)
  {
    if(a[i]>='0'&&a[i]<='9')
    {
            if(count==0){start=i;}
        if(count%2==0)
        {odd=odd+(a[i]-'0');}
        else
        {even=even+(a[i]-'0');}
        if(count==8){end = i;}
     ++count;
    }
    if(count==13&&even>=odd)
    {
   
    for(j=start;j<=end;j++)
        {a[j]='*';}
count=0;even=0;odd=0;start=0;end=0;
    }
    else if(count==13){ count=0;even=0;odd=0;start=0;end=0;}
  }
 // printf("%d %d %d %d\n",start,end,even,odd);

  for(i=0;i<strlen(a);i++)
  {
      printf("%c",a[i]);
    }
 return 0;
}

OUTPUT:

No comments:

Post a Comment