14-10-2005, 12:32
|
|
|
חבר מתאריך: 24.06.02
הודעות: 2,531
|
|
אני אתן לך
אתן לך משהו שכבתי די מזמן זה אמור לקבל מספר ולחק אותו לספרות (כל גודל של מספר) וגם להדפיס כל ספרה.. אתה תוציא מזה את הספרה הגדולה ביותר (כולה להתחיל עם משתנה MAX).
קוד:
using System;
namespace ReadANDCheckNum
{
class ReadNum
{
publicstaticstring RDNum(string rst)
{
if (rst == null)
{
Console.Write("Enter Num: ");
rst = Console.ReadLine();
}
return rst;
}
}
class CheckConvNum
{
publicstaticbool NumChk(refstring buff)
{
bool CachBOOL = true;
decimal num1 = 0;
try
{
num1 = Convert.ToDecimal(buff);
}
catch (ArgumentException)
{
Console.Write("No value was entered... (equal to null). \nPlease Enter Again,");
CachBOOL = false;
}
catch (OverflowException)
{
Console.Write("You entered a number that is too big or too small. \nPlease Enter Again,");
CachBOOL = false;
}
catch (FormatException)
{
Console.Write("You didn't enter a valid number. \nPlease Enter Again, ");
CachBOOL = false;
}
catch (Exception ex)
{
Console.Write("Something went wrong with the conversion. \nPlease Enter Again,");
throw (ex);
}
if (CachBOOL == false)
{
buff = null;
returnfalse;
}
else
returntrue;
}
}
}
namespace Math_conv
{
/*
class arr
{
public reverC (params int[] args)
{
do
{
int[] rev = new int[{args.Length)];
}
while (false);
for (int i=0; i<args.Length ; i++ )
{
rev[(args.Length-i)] =
*/
class NegtoPos
{
publicstaticdecimal ntp(decimal num)
{
if (num < 0)
{
num = (-num);
Console.Write("The Number is: Negative - \"-\"");
}
return num;
}
}
class check
{
publicstaticint xcng;
publicstaticvoid dotc(decimal copy)
{
short ctr = 0; short ctrrev = 0;
copy = copy - (long)copy;
while ((copy-(long)copy)<1 && (copy-(long)copy)!=0)
{
copy = copy*10;
ctr++;
}
Console.WriteLine("...The Numbers after the dot are :...");
ctr = HowManyZero(copy, ctr);
ctrrev = ctr;
check.xcng = ctr;
while (ctrrev > 0)
{
Console.WriteLine("num number - {0} is 0 ", (ctr-(ctrrev-1)));
ctrrev--;
}
ShowNU.dotornext = true ;
ShowNU.readec(copy);
ShowNU.dotornext = false;
}
publicstaticshort HowManyZero(decimal num,short ctr)
{
while (num != 0)
{
num = (long)(num/10);
ctr--;
}
return ctr;
}
}
class ShowNU
{
publicstaticbool dotornext = false;
publicstaticvoid readec(paramsdecimal[] args)
{
decimal x = 1,copy =0; int num = 1, RN = 0; bool tf = true;
for (int i = 0; i < args.Length; i++)
{
//check.xcng = 1;
args[i] = NegtoPos.ntp(args[i]);
copy = args[i];
if (dotornext == false)
{
Console.WriteLine("");
Console.WriteLine("Number: ");
}
x = 1; num = check.xcng; tf = true;
while (tf == true)
{
if ((args[i] / x) < 10)
{
while (x >= 1)
{
if ((args[i] / x) < 1 )
{
Console.WriteLine("num number - {0} is 0", num);
goto dividex;
}
RN = (int)(args[i] / x);
Console.WriteLine("num number - {0} is {1}", num+1, RN);
args[i] = (args[i] - (RN * x));
dividex:
x = x / 10;
num++;
}
tf = false;
}
else
{
x = x * 10;
}
}
try
{
if (copy - (long)copy != 0)
Math_conv.check.dotc(copy);
}
catch
{
Math_conv.check.dotc(copy);
}
}
}
}
class Start
{
publicstaticvoid Main(string[] args)
{
decimal VAL;
string redo;
obj rcc = new obj();
ReadStart: rcc.finish();
VAL = rcc.num;
ShowNU.readec(VAL);
Console.WriteLine("num:{0} buff:{1} \n\n Do you want to Enter another number press Y for YES -or- N for NO? ",rcc.num,rcc.buff);
redo = Console.ReadLine();
if (redo == "Y" || redo == "y")
goto ReadStart;
}
}
class obj
{
publicstring buff; publicbool exChk; publicdecimal num;
public obj() { buff = null; }
public obj(string buff1)
{
buff = buff1;
}
publicvoid Read()
{
buff = ReadANDCheckNum.ReadNum.RDNum(buff);
}
publicvoid ConvAndChk()
{
exChk = ReadANDCheckNum.CheckConvNum.NumChk(ref buff);
}
publicvoid finish()
{
Read();
ConvAndChk();
if (exChk)
num = Convert.ToDecimal(buff);
else
finish();
}
}
}
תאמת שאני לא כל כך זוכר מה קורה שם אבל אם זה עוזר לך אז למה לא ?
|