write a Chinese remainder program in c and java with an output
by using these instructions
In c language:-
#include<stdio.h>
#include<stdlib.h>
long long int MultiplicativeInverse(long long int e,long long int mod)
{
long long int i;
for(i=1;i<mod;i++)
if((e*i)%mod==1)
return i;
}
int main()
{
long long int i,n,*a,*b,*m,M,*Marray,answer;
printf("Enter the number of Equations : \n");
scanf("%lld",&n);
a=(long long int*)malloc(sizeof(long long int)*n);
m=(long long int*)malloc(sizeof(long long int)*n);
Marray=(long long int*)malloc(sizeof(long long int)*n);
printf("Enter the array a :\n");
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
printf("Enter the array m (all the elements of m should be pairwise co-prime) :\n");
for(i=0;i<n;i++)
scanf("%lld",&m[i]);
M=1;
for(i=0;i<n;i++)
M*=m[i];
for(i=0;i<n;i++)
Marray[i]=M/m[i];
answer=0;
for(i=0;i<n;i++)
answer = (answer + ((a[i] * Marray[i])%M * MultiplicativeInverse(Marray[i],m[i]))%M)%M;
printf("x = %lld\n",answer);
return 0;
}
Input:
m[] = { 3, 5, 7 }; a[] = { 2, 3, 2 };
Output: 23
In java:
import java.io.*;
class GFG {
static int inv(int a, int m)
{
int m0 = m, t, q;
int x0 = 0, x1 = 1;
if (m == 1)
return 0;
while (a > 1)
{
q = a / m;
t = m;
m = a % m;a = t;
t = x0;
x0 = x1 - q * x0;
x1 = t;
}
if (x1 < 0)
x1 += m0;
return x1;
}
static int findMinX(int num[], int rem[], int k)
{
int prod = 1;
for (int i = 0; i < k; i++)
prod *= num[i];
int result = 0;
for (int i = 0; i < k; i++)
{
int pp = prod / num[i];
result += rem[i] * inv(pp, num[i]) * pp;
}
return result % prod;
}
public static void main(String args[])
{
int num[] = {3, 4, 5};
int rem[] = {2, 3, 1};
int k = num.length;
System.out.println("x is " +findMinX(num, rem, k));
}
}
Output: 11
write a Chinese remainder program in c and java with an output by using these instructions
WRITE A JAVA PROGRAM . (WILL GUARANTEE A THUMBS UP) BELOW ARE INSTRUCTIONS: IF USER ENTERS: "1, 2, 3" THIS IS THE Expected Output: 1,1,2,2,3,3
in JAVA write a program that produces the following output using nested for loops: +------+ | ^^ | | ^ ^ | |^ ^| | ^^ | | ^ ^ | |^ ^| +------+ | vv | | v v | |v v| | vv | | v v | |v v| +------+
In the following graph, write a Java program using Topological Sort. please write java code and show me the output. Thank you :) b.
Using Java, write a program that contains an array. The array will contain the titles of your favorite books, games, shows, or movies. You may make it as large as you desire, but only enter the titles through user input. Sample output: “Dragon Wing”, “Doom Patrol”, “Pokemon”, “Star Wars” NOTE: Include step-by-step instructions in hidden notes.
use java thanks 1.Given the following arrays, write a Java program to generate the output below. String [] item = {"milo", "water", "coke", "tea", "coffee"}; double [] price = {3.00, 1.00, 5.00, 2.00, 3.50}; int [] quantity = {200, 500, 350, 100, 700}; Re-write Question 1 using array list and display the sale of the day report. Re-write Question 1 using 2-dimensional array and display the sale of the day report. Write a segment program to replace...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
JAVA Program According to Sample output to write a program Sample output: Please enter the number of student: 4 Please enter the score of student 1: 82 Please enter the score of student 2: 92 Please enter the score of student 3: 84 Please enter the score of student 4: 74 --------------------------------------------------- Student Score Grade 1 82 B 2 92 A 3 84 B 4 70 C
Problem 1. Solve the following simultaneous congruence using the Chinese Remainder or the substitution method. a: 2 (mod 5) a: 0 (mod 7) a: = 1 Problem 1. Solve the following simultaneous congruence using the Chinese Remainder or the substitution method. x = 2 (mod 5) x = 0 (mod 7) El mod 17)
Using a single cout statement, write a c++ program to produce the following output. "#//'Baton // @ \\ Rouge'\\#" Write a c++ program, using one cout statement that will output the following: ”\%”BEARS”/%”
how to write a java program that creates a signal generator with an oscillator output of frequency, duration & amplification with the frequency, duration & amplification being input by the user?