Friday, January 19, 2018

Coding test Question : read start and end numbers and print nos whose digits are unique

/*  i/p  :   (120,130)    o/p :  120 123 124 125 126 127 128 129 130 */

#include<stdio.h>
void main()
{
 int temp,sr,er,i,a[5],j,k,l,flag=0;
 clrscr();
 scanf("(%d,%d)",&sr,&er);
 for(i=sr;i<=er;i++)
 {
  temp=i;
  j=flag=0;
  while(temp!=0)
  {
   a[j]=temp%10;
   temp=temp/10;
   j++;
  }
  for(k=0;k<j;k++)
  {
   for(l=k+1;l<j;l++)
   {
    if(a[k]==a[l])
    {
     flag=1;
     break;
    }
   }
   if(flag==1)
   {
    break;
   }
  }
  if(flag!=1)
   printf("%d ",i);
 }
}

No comments:

Post a Comment