Monday, March 25, 2013
C#: Check the month, input from the keyboard how many days
//Lets enter the month and year from the keyboard. Check to see that month how many days.
class Program {
static void Main () {
int m, y;
Console.Write ("Enter a month:");
m = int.Parse (Console.ReadLine ());
Console.Write ("Enter the year:");
y = int.Parse (Console.ReadLine ());
switch (m) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
Console.WriteLine ("{0} No 31 Date", m);
break;
case 4:
case 6:
case 9:
case 11:
Console.WriteLine ("30-day months {0}", m);
break;
case 2:
if ((y% 4 == 0 && y% 100! = 0) | | (y% 400 == 0))
Console.WriteLine ("{0} No 29 Date", m);
else
Console.WriteLine ("{0} No 28 Date", m);
break;
}
Console.ReadLine ();
}
}
Friday, March 22, 2013
C#: Write a program to print to the screen the numbers from 1 to 6 (basic)
//Requirements: Write a program to print to the screen the numbers from 1 to 6 as follows:
1
12
123
1234
12345
123456//Code:
class Program{
static void Main()
{
for (int i = 1; i < 7; i++) {
for (int j = 1; j <= i; j++)
Console.Write(j);
Console.WriteLine();
}
Console.ReadLine();
}
}
Thursday, March 21, 2013
C#: Permutation two integer numbers
//Example: Write a program with type Console Application, enter two numbers a and b. Take two of these permutations. For example: a = 5, b = 7 => a = 7, b = 5.
namespace Example_Permutation{
class Program{
static void Main (){
int a, b, temp;
Console.Write ("Enter A:");
a = int.Parse (Console.ReadLine ());
Console.Write ("Enter B:");
b = int.Parse (Console.ReadLine ());
/ / Use intermediate variable temp to store the swap value of a, b
temp = a;
a = b;
b = temp;
Console.WriteLine ("The value of a = {0}, b = {1}", a, b);
Console.ReadLine ();
}
}
}
Wednesday, March 20, 2013
C#: Calculate the total of 3 digits from the 3-digit integer n (input from the keyboard).
//Example: Write a program with type Console Application, enter the 3-digit integer n. Please calculate the total 3 digits.
namespace BaiThucHanh1
{
class Program
{
static void Main (){
int n;
Console.Write ("Enter n:");
n = int.Parse (Console.ReadLine ());
int s = 0;
int balance;
while (n! = 0) {
balance = n % 10;
s+=balance;
n = n / 10;
}
Console.WriteLine ("The total of 3 digits is: {0}", s.ToString ());
Console.ReadLine ();
}
}
}
C#: Enter two variables a, b (integer). Calculate the total and the results on the screen.
//Example: Write a program with type Console Application, enter two integers a, b. Please calculate the total and the results on the screen.
using System;
namespace Total{
class Program{
static void Main (){
int a, b;
Console.Write ("Enter first integer:");
a = int.Parse (Console.ReadLine ());
Console.Write ("Enter second integer:");
b = int.Parse (Console.ReadLine ());
Console.WriteLine (a + b);
Console.ReadLine ();
}
}
}
Tuesday, March 19, 2013
Access: CREATE TABLE Statement
'Example: Creates a new table called ThisTable with two text fields.
Sub CreateTable1()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Create a table with two text fields.
dbs.Execute "CREATE TABLE ThisTable(FirstName CHAR, LastName CHAR);"
dbs.Close
End Sub
Sub CreateTable1()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = OpenDatabase("Northwind.mdb")
' Create a table with two text fields.
dbs.Execute "CREATE TABLE ThisTable(FirstName CHAR, LastName CHAR);"
dbs.Close
End Sub
Monday, March 18, 2013
C#: Calculate the factorial of n
//Example 3. Write a program with a Console Application, the factorial of n raw keyboard input.
class Program
{
static void Main ()
{
int n;
int GT = 1;
Console.Write ("Enter the number of n identity factorial:");
n = int.Parse (Console.ReadLine ());
for (int i = 2; i <= n; i + +)
GT * = i;
Console.WriteLine ("The factorial of {0} is: {1}", n, GT);
Console.ReadLine ();
}
}
Saturday, March 16, 2013
C#: An example about FOR loop
/ / Example 1: Write a C # program using FOR in structure to the screen the results are as follows:
*******
******
*****
****
***
**
*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FOR_1 {
class Program {
static void Main (string [] args) {
int i, j;
for (i = 0; i <= 6; i + +) {
for (j = 1; j <= 7-i; j + +) Console.Write ("*");
Console.Write ("\ n");
}
Console.ReadLine ();
}
}
}
Thursday, March 14, 2013
C#: Date Time Client - Socket Programming
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
namespace Client{
class DateTimeClient {
static void Main(string[] args) {
IPEndPoint iep = new IPEndPoint(IPAddress.Parse("127.0.0.1"),2009);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Connect(iep);
NetworkStream ns = new NetworkStream(client);
StreamReader sr = new StreamReader(ns);
StreamWriter sw = new StreamWriter(ns);
while (true) {
string input = Console.ReadLine();
sw.WriteLine(input);
sw.Flush();
if (input.ToUpper().Equals("QUIT")) break;
string kq = sr.ReadLine();
Console.WriteLine(kq);
}
sr.Close();
sw.Close();
ns.Close();
}
}
}
C#: Start Process Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace Demo_Thread{
public class StartProcessExample{
static void Main(string[] args){
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "notepad++.exe"; startInfo.Arguments = "noominhee.txt"; startInfo.WorkingDirectory = @"G:\LTW3\2";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.ErrorDialog = true;
using (Process process = new Process()) {
process.StartInfo = startInfo;
try{
process.Start();
Console.WriteLine("Waiting 30 seconds for process to" + " finish.");
process.WaitForExit(30000);
}
catch (Exception ex) {
Console.WriteLine("Could not start process.");
Console.WriteLine(ex);
}
}
Console.WriteLine("Main method commplete. Press Enter.");
Console.ReadLine();
}
}
}
Subscribe to:
Posts (Atom)