For Q2 I've Got
Code:
namespace Ch04Q02
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
int myInt1,myInt2;
Console.WriteLine("Please enter an integer:");
do
{
myInt1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Now enter another integer:");
myInt2 = Convert.ToInt32(Console.ReadLine());
if (myInt1>10 && myInt2>10)
Console.WriteLine("Both numbers must be less then 10!\nPlease enter you first number again.");
}
while (myInt1>10 && myInt2>10);
Console.WriteLine("Sum of ints<10? {0}", (myInt1 + myInt2) < 10);
Console.WriteLine("Sum of ints between 0 and 5? {0}",
(0 <= myInt1 + myInt2) && (myInt1 + myInt2 <= 5));
Console.WriteLine("Bitwise AND of int sum and 10 = {0}", myInt1 + myInt2 & 10);
}
}
}
And for Q4 I've got
Code:
using System;
namespace Ch04Q04
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
double realCoord, imagCoord;
double realTemp, imagTemp, realTemp2, arg;
double realMin=-0.6,realMax=1.77,imagMin=-1.2,imagMax=1.2; //limits
double realInc=0.03,imagInc=0.05; //increments
//get limits
Console.WriteLine("Please enter the min Real coord {0}:",realMin);
realMin=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter the max Real coord {0}:",realMax);
realMax=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter the min Imaginary coord {0}:",imagMin);
imagMin=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please enter the max Imaginary coord {0}:",imagMax);
imagMax=Convert.ToDouble(Console.ReadLine());
//work out inc's
imagInc=(imagMax-imagMin)/48;
realInc=(realMax-realMin)/78; //uh why not 79??
int iterations;
for (imagCoord=imagMax;imagCoord>=imagMin;imagCoord-=imagInc)
{
for (realCoord=realMin; realCoord<=realMax;realCoord+=realInc)
{
iterations=0;
realTemp=realCoord;
imagTemp=imagCoord;
arg=(realCoord*realCoord)+(imagCoord*imagCoord);
while((arg<4)&&(iterations<40))
{
realTemp2=(realTemp*realTemp)-(imagTemp*imagTemp)-realCoord;
imagTemp=(2*realTemp*imagTemp)-imagCoord;
realTemp=realTemp2;
arg=(realTemp*realTemp)+(imagTemp*imagTemp);
iterations+=1;
}
switch (iterations %4)
{
case 0:
Console.Write(".");
break;
case 1:
Console.Write("o");
break;
case 2:
Console.Write("O");
break;
case 3:
Console.Write("x");
break;
}
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}