Reference no: EM13938500
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;
}