Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

what is wring with this code in visual studio C#, console application: Console.W

ID: 3680265 • Letter: W

Question

what is wring with this code in visual studio C#, console application:

Console.WriteLine("please provide a whole number");
int theNumber = Convert.ToInt32(Console.ReadLine());
}
bool is prim
for(int i = 2;i<= theNumber ; i++);
  
prim=true;

if(theNumber % i == 0)
{
is prime= false;
}
}
if( is prime = true);

console.WriteLine("your number is prime")
}
else
{
for (int j = 1; j< thenumber+1; j++)

console.Writeline("the factor of your number are")
{
if(the number % j==0)
{
console.writeline(j);
}
}
}
console.Readline();

Explanation / Answer

//There where large number of syntax and logical errors in your code.I have modified and written a working code

namespace example
{
class program
{
public static void Main()
{
Console.Write("Enter a Number : ");
int theNumber,i,j=0;
theNumber = Convert.ToInt32(Console.ReadLine());
  

for ( i = 1; i <= theNumber; i++)
{
if (theNumber % i == 0)
{
j++;
}
}
if (j == 2)
{
Console.WriteLine("Entered Number is a Prime Number and the Largest Factor is {0}", theNumber);
}
else
{
Console.WriteLine(" Entered number is not a prime number");
}
Console.ReadLine();
}
}
}