Share
Explore BrainMass

# Chinese Remainder Theorem in Visual C++.NET 2003

I need help to writing a program "VC++.net"with the specified input and output.

Please, Implement the Chinese Remainder Theorem. Allowing at least 3 pairwise relatively prime positive integers.

Please attention
This program must run in the Visual C++.NET. Some time I have problem with that, so, please the whole project included in the attached Zip file.

I already tried writing this program but I couldn't run it. I send that, I hope be useful.

//project #1

#include <iostream.h>
#include <stdlib.h>
#include <math.h>

int gcd(int,int);
int inverse(int,int);

void main(){

int x, Remainder[4], Num[4], M=1, Ma[4], Myarray[4]={0,0,0,0},i;

for (i=0; i<4; i++)

{

cout<<" nn X = A (MODULUS M) nn";
cout<<" PLEASE ENTER YOUR NUMBER :nnn ";
cin>>Remainder[i];
cout<<" PLEASE ENTER YOUR NEXT NUMBER :nnn";

cin>>Num[i];
cout<<" AND NOW YOUR NUMBER IS = "

<< Remainder[i] << " ( mod " << Num[i]<< " ) ";

M = M * Num[i];

cout<<M<<"n";

Ma[i] = M/Num[i];
cout<< " nn M = "<< Ma[i] << "Modulus" << Num[i]<<" ( "<< Ma[i] <<" = "<< Remainder[i]<<" )n";

Myarray[i]= gcd(Ma[i], Num[i]);
Myarray[i]= inverse(Ma[i], Num[i]);

x=Remainder[0]*Ma[0]*Myarray[0]+Remainder[1]*Ma[1]*Myarray[1]+Remainder[2]*Ma[2]*Myarray[2];
x=x%M;
cout <<endl;
cout<<" x = "<<x<<" ( Mod"<<M<<" )n";
}

system ("pause");
}
int inverse(int a, int b)
{
int x=1;

while (a*x%b !=1)
{
x++;
}
return x;
}

int gcd(int Num, int n)
{

int Remainder;
while (n!=0)
{
Remainder = Num %n;
Num=n;
n=Remainder;
}
return Num;
}

#### Solution Preview

I have made your program to run in VS.net - the zip file is attached

As regards the content - it is not very clear what you want to be done.

There is a link to a web page on the subject:

http://www.cut-the-knot.org/blue/chinese.shtml

Do you want the program to be rewritten completely to perform the action ...

#### Solution Summary

The Chinese remainder theorem for visual C++ NET 2003 is examined. Three pairwise relatively prime positive integers are determined.

\$2.19