Question

C#, I am getting error placing them all in one file pls set them in the...

C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks

//Program 1

using System;
class MatrixLibrary
{
public static int[,] Matrix_Multi(int[,] a, int [,]b){
int r1= a.GetLength(0);
int c1 = a.GetLength(1);
int c2 = b.GetLength(1);
int r2 = b.GetLength(0);
if(r2 != c2){
Console.WriteLine("Matrices cannot be multiplied together.\n");
return null;
  
}else {
int[,] c = new int[r1, c2];
for (int i = 0; i < r1; i++)
{
for (int j = 0; j < c2; j++)
{
c[i, j] = 0;
for (int k = 0; k < c1; k++)
{
c[i, j] += a[i, k] * b[k, j];
}
}
}
return c;
  
}
}
public static string MatrixToString(int[,] a){
string str = "";
int p= a.GetLength(0);
int q = a.GetLength(1);
for (int i = 0; i < p; i++) {
for (int j = 0; j < q; j++) {
str = str + string.Format("{0,-4}",a[i,j]);
}
str = str + "\n";
}
return str;
}
static void Main()
{
int[,] a = {{1, 4, 2}, {2, 5, 1}};
int[,] b = {{3, 4, 2}, {3, 5, 7}, {1, 2, 1}};
Console.Write(MatrixToString(Matrix_Multi(a,b)));
  
Console.WriteLine();
int[,] P = {{10, 5, 20}, {20, 1, 7}, {10, 15, 12}};
int[,] Q = {{31, 24, 32}, {6, 2, 9}, {10, 22, 11}};
Console.Write(MatrixToString(Matrix_Multi(P,Q)));
  
Console.WriteLine();
int[,] m = {{3, 4, 2}, {3, 5, 7}, {1, 2, 1}};
int[,] n = {{1, 4, 2}, {2, 5, 1}};
Matrix_Multi(m,n);
}
}

//Program 2

using System;


namespace Delegates
{
public delegate int MyMathFunction(int x,int y);
class Program
{
static void Main(string[] args)
{
MyMathFunction myMathFunction = new MyMathFunction( Subtract);
int result = myMathFunction(7, 4);
MyMathFunction myMathFunction2 = new MyMathFunction(Multiply);
int result2 = myMathFunction2(5, 4);
MyMathFunction myMathFunction3 = new MyMathFunction(Divide);
int result3 = myMathFunction3(4, 2);
MyMathFunction myMathFunction4 = new MyMathFunction(Add);
int result4 = myMathFunction4(7, 4);
Console.WriteLine(result);
Console.WriteLine(result2);
Console.WriteLine(result3);
Console.WriteLine(result4);

}
  

public static int Add(int x, int y)
{
return (x + y);
}
public static int Multiply(int x, int y)
{
return (x * y);
}
public static int Divide(int x, int y)
{
int div = 0;
try
{
div = x / y;
}
catch (DivideByZeroException d)
{
Console.WriteLine("Cannot divide by zero");
return -1;
}
return div;
}
public static int Subtract(int x, int y)
{
return (x - y);
}

}

}

//Program 3

using System;

namespace MyPrime

{

    public class Solution

    {

        public static bool isPrime(int n, int i)

        {

            if( n < 2 )

                return false;

            else if( n == 2 )

               return true;

            else if( i >= n )

                return true;

            else if( n % i == 0 )

                return false;

            else

                return isPrime(n, i + 1);

        }

           

        public static void Main(string[] args)

        {

            Console.WriteLine("Enter n : ");

           

            int n = Convert.ToInt32(Console.ReadLine());

           

            if( isPrime(n, 2) == true )

                Console.WriteLine(n + " is a Prime Number");

            else

                Console.WriteLine(n + " is not a Prime Number");

        }

    }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the complete code in one file from the link below:

https://www.dropbox.com/s/0kbss1kdihj7eza/ConsoleApplication1.zip?dl=0

Add a comment
Know the answer?
Add Answer to:
C#, I am getting error placing them all in one file pls set them in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • Greetings everyone I am having a little trouble with this one. I bolded my switch case...

    Greetings everyone I am having a little trouble with this one. I bolded my switch case which should work but its currently not. If a user selected course option 1 twice it just says you enrolled in course 1 and course 1. It should stop it by executing case -2. Need a new set of eyes. - Thanks using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleRegisterStudent { class Program { static void Main(string[] args) { (new...

  • [C#] I need to convert this if/else statements into Switch I have the code for the...

    [C#] I need to convert this if/else statements into Switch I have the code for the if/else but now need to turn it into a switch. The Console.WriteLine and all that is fine. I just need to convert the if/else.      int x1, x2, y1, y2;                 Console.WriteLine("What is smallest value of x:");                 x1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of x:");                 x2 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is smallest value of y:");                 y1 = Convert.ToInt32(Console.ReadLine());                 Console.WriteLine("What is largest value of y:");                 y2 =...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • So I am working on an assignment where we make a rudimentary browser history with c#....

    So I am working on an assignment where we make a rudimentary browser history with c#. The requirement is that we need to use a linked list to do this. The issue that I am having is that when I want to go backwards in the history and print it takes from the beginning of the list and not the front. (Example is if I had a list with 1, 2, 3, 4 in it and went back It would...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • Where in the c# code can i enter the information to print to console?   Console.WriteLine("Pattern found...

    Where in the c# code can i enter the information to print to console?   Console.WriteLine("Pattern found at:{0}", i); Console.WriteLine(pattern) public void preKMP() { int m = pattern.Length; int k; f[0] = -1; for (int i = 1; i < m; i++) { k = f[i - 1]; while (k >= 0) { if (pattern[k] == pattern[i - 1]) break; else k = f[k]; } f[i] = k + 1; } } public int Search() // s is string sequence, pattern...

  • I cannot figure out why my removeAll for var = 7 is not working. using System;...

    I cannot figure out why my removeAll for var = 7 is not working. using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnorderedArrayListNamespace; namespace Array { public class Program { public static void Main(string[] args) { UnorderedArrayList u = new UnorderedArrayList(); u.print(); int var = 5; u.insert(ref var); var = 12; u.insert(ref var); var = 2; u.insert(ref var); var = 29; u.insert(ref var); var = 7; u.insert(ref var); var = 33; u.insert(ref var); var = 49; u.insert(ref var); var...

  • Create a method based program to find if a number is prime and then print all...

    Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod {    public static void main(String[] args)    {       String input;        // To hold keyboard input       String message;      // Message...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT