Sunday, April 15, 2012

Program 16TH VERSION 2 in C++

PROBLEM STATEMENT :

Calculate number of zeros in a given integer in binary format.

SOLUTION :


#include <iostream.h>
#include <cstdio>

using namespace std;

void count(int num)
{

int count=0;

while(num>0)
{
count+=!(num & 1);
num=num>>1;
}

cout<<"\n\nThe number of zeros in the given string are : "<<count<<endl;
}

int main()
{

int number;

count (3);
count(0);
count('\0');

}

No comments:

Post a Comment