My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Saturday, 19 January 2013

C Logic


 Assume The Motor Vehicles Department has notified numbers between 1000 and 9999(both inclusive) as available for the new series KL-35 A. Write a program to print all fancy numbers in this series. Following
are the conditions for fancy numbers:

   1. All digits are the same.
   2. Sum of all digits added until getting a single digit gives the number 9.


//find fancy number


#include<stdio.h>
#include<conio.h>
int all_the_same(int x);
void main()
{

int n,s=0,sum=0,i,d,kond;
clrscr();
printf("Fancy numbers between 1000 and 9999 are");

for(kond=1000;kond<=9999;kond++)

{  
n=kond;s=0;sum=0;
if(all_the_same(n)==1)
{
printf("\n%d  ", n);
getch();
}
else
{

while(n>0)
{
d=n%10;
s=s+d;
n=n/10;
}
while(s>0)
{
i=s%10;
sum=sum+i;
s=s/10;
}
if(sum==9)
{
printf("\n%d  ",kond);
getch();

}

}

}
getch();
}

 int all_the_same(int x)
{
int cnt=0;
    int digit = x%10;


    while(x>0)
    {
        if((x%10) != digit)
         cnt++;
        x = x/10;
    }

 if(cnt==0)
{
cnt=0;
    return 1;
}
else
{
  return 0;
}
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.