usingSystem;
classMainClass{staticvoidswap(){}publicstaticvoidMain(string[] args)
{int sum = 0;
Console.Write("Enter a: ");
int a = int.Parse(Console.ReadLine());
Console.Write("Enter b: ");
int b = int.Parse(Console.ReadLine());
swap();
Console.WriteLine("Swap a and b");
Console.WriteLine("a={0} b={1}",a,b);
Console.ReadKey();
}}
ข้อ 3
usingSystem;
classRefExample{staticvoidReadTwoNums()
{
Console.WriteLine("Enter two number:");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
}staticvoidMain()
{int n1 = 0, n2 = 0;
ReadTwoNums();
Console.WriteLine("Numbers are {0} and {1}", n1, n2);
Console.ReadKey();
}}
ข้อ 4
usingSystem; 2: classMainClass{ 3: staticvoidReadPoint( ) 4: { 5: Console.Write("Enter x-coordinate: "); 6: x = double.Parse(Console.ReadLine()); 7: Console.Write("Enter y-coordinate: "); 8: y = double.Parse(Console.ReadLine()); 9: } 10: 11: staticdoubleDistance( ) 12: { 13: 14: } 15: 16: staticvoidMain() 17: { 18: double ax, ay, bx, by; 19: Console.WriteLine("Point A:"); 20: ReadPoint(out ax, out ay); 21: Console.WriteLine("Point B:"); 22: ReadPoint(out bx, out by); 23: Console.WriteLine("The distance between A and B is {0:f2}", 24: Distance(ax,ay,bx,by)); 25: } 26: }
ข้อ 5
usingSystem;
classMainClass{staticintProfit(int x)
{}staticvoidMain()
{int a, b;
Console.Write("Enter A:");
a = int.Parse(Console.ReadLine());
Console.Write("Enter B:");
b = int.Parse(Console.ReadLine());
int best = Profit(a);
int bestAt = a;
Console.WriteLine("Best profit is {0} at {1}", best, bestAt);
}}
ข้อ 6
usingSystem; classMainClass{ staticint h, d, n;
/* this method checks if y is out of the well of depth h */ staticboolIsOut(int y, int h) {
}
staticvoidClimbUp(refint y) {
}
staticvoidFallDown(refint y) {
}
staticvoidMain() {
h = int.Parse(Console.ReadLine());
d = int.Parse(Console.ReadLine());
n = int.Parse(Console.ReadLine());
int day = 1; int y = 0; while(!IsOut(y,h)) {
day++; }
Console.WriteLine("Get out on day {0}", day); } }
ข้อ 7
usingSystem;
classMainClass{/* method IsSquare checks if y is a square. */staticboolIsSquare(int y)
{}/* method IsSquareFactor checks if f is a square factor of x */staticboolIsSquareFactor(int f, int x)
{}publicstaticvoidMain(string[] args)
{int x = int.Parse(Console.ReadLine());
int i = 1;
while()
{if()
Console.Write("{0} ", );
i++;
}
Console.WriteLine();
}}
{
StreamReader reader = int a = int.Parse(); int b = int c =
Console.WriteLine(a+b+c);
Console.ReadLine();
reader. } } }
ข้อ 12
usingSystem;
usingSystem.IO;
namespacehellofile{classProgram{publicstaticvoidMain(string[] args)
{
StreamReader reader =
int n = int.Parse();
int i = 0;
int total = 0;
while(i < n)
{}
Console.WriteLine(total);
Console.ReadLine();
reader.Close();
}}}
ข้อ13
usingSystem;
usingSystem.IO;
namespacemoving_average{classProgram{staticvoidUpdate()
{}publicstaticvoidMain(string[] args)
{
StreamReader reader = new StreamReader("input.txt");
int n = 0;
double total = 0;
double avr = 0;
double x;
do{
x = double.Parse(reader.ReadLine());
if(x != 0)
{
Update();
Console.WriteLine("{0:f3} {1:f3}", total, avr);
}}while();
reader.Close();
Console.ReadLine();
}}}
Pb4) 4.1) if (d>=h) return true; if (y>=h) return true; else return false;
4.2) y+=d;
4.3) y-=n;
4.4) ClimbUp(ref y); if (y0) plus ++; else minus ++; x = int.Parse(Console.ReadLine()); }
6.3) out plus,out minus
Pb7.1) using System; using System.IO;
namespace hellofile { class Program { public static void Main(string[] args) { StreamReader reader = new StreamReader("name.txt"); string name = reader.ReadLine(); string a = reader.ReadLine(); Console.WriteLine(name); Console.WriteLine(a); Console.ReadLine(); reader.Close(); } } }
Pb7.2) using System; using System.IO;
namespace hellofile { class Program { public static void Main(string[] args) { StreamReader reader = new StreamReader("name.txt"); string name = reader.ReadLine(); string a = reader.ReadLine(); Console.WriteLine(a); Console.WriteLine(name); Console.ReadLine(); reader.Close(); } } }
Pb7.3) 7.3.1) using System.IO;
7.3.2) new StreamReader("numbers.txt");
7.3.3) reader.ReadLine()
7.3.4) int.Parse(reader.ReadLine());
7.3.5) int.Parse(reader.ReadLine());
7.3.6) Close();
Pb8) 8.1) new StreamReader("input.txt");
8.2) reader.ReadLine()
8.3) int s = int.Parse(reader.ReadLine()); { if (s >= 0) total = total + s;
} i++;
Pb9) 9.1) ref int n,ref double total,ref double avr,ref double x
9.2) if (x!=0){ total += x; avr = total/(n+1); n++; }
9.3) ref n,ref total, ref avr,ref x
9.4) x!=0
Pb10) 10.1) static double total = 0; static double avr = 0; static int i = 1;
10.2) total+=x; avr = total/i; i++;
10.3) x!=0
Pb11) using System; using System.IO;
namespace hellofile { class Program { public static void Main(string[] args) { StreamReader reader = new StreamReader("input.txt"); int n = int.Parse(reader.ReadLine()); int i = 1; int a = 0; int b = 0; int c = 0; while (i<=n) { string x = reader.ReadLine(); if (x=="A") a++; else if (x=="B") b++; else if (x=="C") c++; i++; } Console.Write("{0} {1} {2}",a,b,c); Console.Read();
} } }
Pb bonus)
using System;
namespace program { class Program { static int x=1,ans=0,eror=0; static string y; static int low=0, high=1001;
public static void Main(string[] args) { while (true) { x = int.Parse(Console.ReadLine()); if (x==0) break; y = Console.ReadLine(); if (y=="E") ans = x; else if (y=="L") if (x>=low) low = x; if (low>=high) eror = -1; else if (y=="H") if (x<=high) high = x; if (high<=low) eror = -1; } //Console.WriteLine("{0},{1},{2}",high,low,eror); if(high>=1001 || low <=0){ Console.WriteLine("No solution"); } else if(ans<=low && ans!=0){ Console.WriteLine("No solution"); } else if(high-low==2) { Console.WriteLine("Solution is {0}",low+1); } else if(ans!=0) { Console.WriteLine("Solution is {0}",ans); } else if(high-low>2 || eror!=-1){ Console.WriteLine("Solution in range {0} - {1}",low+1,high-1); } else Console.WriteLine("No solution"); Console.Read(); } } }
Pb1)
ตอบลบ1.1)
ref int a,ref int b
1.2)
int c = a;
a=b;
b=c;
1.3)
ref a,ref b
Pb2)
2.1)
out double x,out double y
2.2)
double ax,double ay,double bx,double by
2.3)
double c = Math.Sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
return c;
Pb3)
3.1)
int a =1000+ (50*x )+(150*x*x)-((int)Math.Pow(x,3));
return a;
3.2)
while(abest)
{best = Profit(a);
bestAt = a;
}
}
Pb4)
4.1)
if (d>=h)
return true;
if (y>=h)
return true;
else
return false;
4.2)
y+=d;
4.3)
y-=n;
4.4)
ClimbUp(ref y);
if (y0)
plus ++;
else
minus ++;
x = int.Parse(Console.ReadLine());
}
6.3)
out plus,out minus
Pb7.1)
using System;
using System.IO;
namespace hellofile
{
class Program
{
public static void Main(string[] args)
{
StreamReader reader = new StreamReader("name.txt");
string name = reader.ReadLine();
string a = reader.ReadLine();
Console.WriteLine(name);
Console.WriteLine(a);
Console.ReadLine();
reader.Close();
}
}
}
Pb7.2)
using System;
using System.IO;
namespace hellofile
{
class Program
{
public static void Main(string[] args)
{
StreamReader reader = new StreamReader("name.txt");
string name = reader.ReadLine();
string a = reader.ReadLine();
Console.WriteLine(a);
Console.WriteLine(name);
Console.ReadLine();
reader.Close();
}
}
}
Pb7.3)
7.3.1)
using System.IO;
7.3.2)
new StreamReader("numbers.txt");
7.3.3)
reader.ReadLine()
7.3.4)
int.Parse(reader.ReadLine());
7.3.5)
int.Parse(reader.ReadLine());
7.3.6)
Close();
Pb8)
8.1)
new StreamReader("input.txt");
8.2)
reader.ReadLine()
8.3)
int s = int.Parse(reader.ReadLine());
{
if (s >= 0)
total = total + s;
}
i++;
Pb9)
9.1)
ref int n,ref double total,ref double avr,ref double x
9.2)
if (x!=0){
total += x;
avr = total/(n+1);
n++;
}
9.3)
ref n,ref total, ref avr,ref x
9.4)
x!=0
Pb10)
10.1)
static double total = 0;
static double avr = 0;
static int i = 1;
10.2)
total+=x;
avr = total/i;
i++;
10.3)
x!=0
Pb11)
using System;
using System.IO;
namespace hellofile
{
class Program
{
public static void Main(string[] args)
{
StreamReader reader = new StreamReader("input.txt");
int n = int.Parse(reader.ReadLine());
int i = 1;
int a = 0;
int b = 0;
int c = 0;
while (i<=n)
{
string x = reader.ReadLine();
if (x=="A")
a++;
else if (x=="B")
b++;
else if (x=="C")
c++;
i++;
}
Console.Write("{0} {1} {2}",a,b,c);
Console.Read();
}
}
}
Pb bonus)
using System;
namespace program
{
class Program
{
static int x=1,ans=0,eror=0;
static string y;
static int low=0, high=1001;
public static void Main(string[] args)
{
while (true)
{
x = int.Parse(Console.ReadLine());
if (x==0)
break;
y = Console.ReadLine();
if (y=="E")
ans = x;
else if (y=="L")
if (x>=low)
low = x;
if (low>=high)
eror = -1;
else if (y=="H")
if (x<=high)
high = x;
if (high<=low)
eror = -1;
}
//Console.WriteLine("{0},{1},{2}",high,low,eror);
if(high>=1001 || low <=0){
Console.WriteLine("No solution");
}
else if(ans<=low && ans!=0){
Console.WriteLine("No solution");
}
else if(high-low==2)
{
Console.WriteLine("Solution is {0}",low+1);
}
else if(ans!=0)
{
Console.WriteLine("Solution is {0}",ans);
}
else if(high-low>2 || eror!=-1){
Console.WriteLine("Solution in range {0} - {1}",low+1,high-1);
}
else
Console.WriteLine("No solution");
Console.Read();
}
}
}
ใรลอกแล้วไม่คิดตาม ระวังนะ จะ ตกเอา
ตอบลบ