ข้อ 1
Console.WriteLine("Live as if you were to die tomorrow.");
Console.WriteLine("Learn as if you were to live forever.");
Console.WriteLine("-Mahatma Gandhi");
ข้อ 2
"Arthur"
18
yourAge
yourName
ข้อ 3
class MainClass
{
public static void Main(string[] args)
{
string x;
Console.Write("Enter your name: ");
x = Console.ReadLine();
Console.WriteLine("Hello, {0}", x);
}
}
ข้อ 4
using System;
class MainClass
{
public static void Main(string[] args)
{
int x,y;
Console.Write("Input Dividend : ");
x = int.Parse(Console.ReadLine());
Console.Write("Input Divisor : ");
y = int.Parse(Console.ReadLine());
int a = x/y;
int b = x%y;
Console.WriteLine("The quotient of {0}/{1} is {2} and the remainder is {3}.", x,y,a,b);
}
}
ข้อ 5
using System;
using System.Collections.Generic;
public class ChangeTemp
{
public static void Main()
{
Console.Write("Input a temperature in degree Celsius : ");
double C = double.Parse(Console.ReadLine());
double F = 9*C/5+32;
Console.Write("{0:f1} degrees Celsius is equivalent to {1:f1} degrees Fahrenheit", C,F);
}
}
ข้อ 6
using System;
using System.Collections.Generic;
public class MyClass
{
public static void Main()
{
Console.Write("Enter m: ");
double m = double.Parse(Console.ReadLine());
Console.Write("Enter f1: ");
double f1 = double.Parse(Console.ReadLine());
Console.Write("Enter t1: ");
double t1 = double.Parse(Console.ReadLine());
Console.Write("Enter f2: ");
double f2 = double.Parse(Console.ReadLine());
Console.Write("Enter t2: ");
double t2 = double.Parse(Console.ReadLine());
double a = (f1*(Math.Cos(t1*Math.PI/180))-f2*(Math.Cos(t2*Math.PI/180)))/m;
Console.WriteLine("a = {0:F4}" ,a);
Console.ReadLine();
}
}
ข้อ 7
int.Parse(Console.ReadLine());
age < 18
ข้อ 8
int.Parse(Console.ReadLine());
s>=80
s>=50
Console.WriteLine("Please try harder.");
ข้อ 9
int.Parse(Console.ReadLine());
(n>=100)&&(n<=200)
ข้อ 10
using System;
class Test
{
static void Main() {
Console.Write("Please input x: ");
int x = int.Parse(Console.ReadLine());
if(x>35)
Console.WriteLine("f(x) = {0:f3}", 2*(x*x*x)-5);
if((x<=35)&&(x>15))
Console.WriteLine("f(x) = {0:f3}", 3*(x*x));
if(x<=15)
Console.WriteLine("f(x) = {0:f3}", 2*x+10);
}
}
ข้อ11
s1-(int)s1;
t1+(s2-(int)s2);
t2+(s3-(int)s3);
t3>1
ข้อ 12
using System;
class Program
{
public static void Main(string[] args)
{
Console.Write("Enter weight: ");
double x = double.Parse(Console.ReadLine())
if(x<1)
Console.WriteLine("It is small.");
if((x>=1)&&(x<3))
Console.WriteLine("It is medium.");
if(x>=3)
Console.WriteLine("It is large.");
}
}
ข้อ 13
Console.Write("Enter N: ");
int.Parse(Console.ReadLine());
i<=n
"{0}", i
i = i+1;
ข้อ 14
0
1
data>0
"Enter data: "
int.Parse(Console.ReadLine());
total += data;
ข้อ15
using System;
class Program
{
public static void Main(string[] args)
{
int total = 0;
int data = 1;
while(data>0)
{
Console.Write("Enter data: ");
data = int.Parse(Console.ReadLine());
int x = data;
if(x%2==0)
total += data;
Console.WriteLine("Total = {0}",total);
}
Console.ReadLine();
}
}
ข้อ16
using System;
class Program
{
public static void Main(string[] args)
{
double sum = 0;
double score = 0 ;
Console.Write("Enter a score, or -1 to quit : ");
score = double.Parse(Console.ReadLine());
while(score!=-1)
{
sum = sum + score;
Console.WriteLine("Now summation is : {0:f1}",sum);
Console.Write("Enter a score, or -1 to quit : ");
score = double.Parse(Console.ReadLine());
}
Console.WriteLine("PROGRAM TERMINATED!!!");
Console.ReadLine();
}
}
ข้อ 17
using System;
class Program
{
public static void Main(string[] args)
{
int n;
Console.Write("Enter number: ");
n = int.Parse(Console.ReadLine());
if (n==0)
Console.WriteLine(0);
while(n>0 )
{
Console.WriteLine(n%10);
n = n/10;
}
Console.ReadLine();
}
}
ข้อ18
using System;
class Program
{
public static void Main(string[] args)
{
int n;
double sum = 0;
int count = 0;
Console.Write("Enter binary number: ");
n = int.Parse(Console.ReadLine());
while(n>0)
{
sum = sum + (n%10)*Math.Pow(2,count);
n /= 10;
count++;
}
Console.WriteLine(sum);
Console.ReadLine();
}
}
แก้ใข ข้อ 12 บรรทัด
ตอบลบdouble x = double.Parse(Console.ReadLine())
ให้เปลี่ยนเป้น
double x = double.Parse(Console.ReadLine());
เพราะลืมใส่ ; มันจะผิดนะ