Wednesday 27 August 2014

Zero Count :) :)

William played a number game with his sister as to count the number of Hole in each of the digit. His sister who is poor in mathematics. We have to help her to count the number of Zeros.

Sample Test Case:
989
4

100
2

1456
1

/* Code to Crack it is */

# include <iostream.h>
# include <conio.h>
int main()
{
 clrscr();
 long int n,sum;
 cin>>n;
 sum=0;
 while(n!=0)
 {
  int r;
  r=n%10;
  //cout<<r;
  if(r==6||r==9||r==0)
       sum=sum+1;
  if(r==8)
       sum=sum+2;
  else
       sum=sum+0;

  r=0;
  n=n/10;
 }
 cout<<sum;
return 00;

No comments:

Post a Comment