Posts tagged ‘common’

February 1, 2011

Finding the least common digit. C++ Programming code


#include<iostream.h>
int gcd(int a,int b)
{
int swap;
while(b>0)
{
swap=b;
b=a%b;
a=swap;
}
return a;
}
int nok(int *b,int n)
{
int result;
if(n==2)
{
return (*(b+0))*(*(b+1))/gcd(*(b+0),*(b+1));
}
else
result=nok(b,n-1);
return (*(b+n-1)*result)/gcd(*(b+n-1),result);
}
void enter(int m,int *b)
{

for(int i=0;i<m;i++)
{
cout<<“input element number:  “<<i+1<<”   “;
cin>>*(b+i);
cout<<“n”;
}
}
void print(int m ,int *b)
{
for (int i=0;i<m;i++)
{
cout<<“element number  “<<i+1<<”   “<<*(b+i)<<“n”;
}
}