Archive for Tháng Mười Một, 2008
Máy tính đơn giản bằng C
Máy tính đơn giản bằng C:
#include<stdio.h>
float add(float,float);
float sub(float,float);
float product(float,float);
float divide(float,float);
void main()
{
float n1,n2;
char sym,choice;
printf("This Program is a program for calculator\n\n");
scanf("%f%c%f",&n1,&sym,&n2);
if(sym=='+')
printf("\n%f",add(n1,n2));
if(sym=='-')
printf("\n%f",sub(n1,n2));
if(sym=='*')
printf("\n%f",product(n1,n2));
if(sym=='/')
printf("%f",divide(n1,n2));
printf("\nDo you wish to continue[y/n]");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
main();
}
float add(float m1,float m2)
{
return(m1+m2);
}
float sub(float m1,float m2)
{
return(m1-m2);
}
float product(float m1,float m2)
{
return(m1*m2);
}
float divide(float m1,float m2)
{
return(m1/m2);
}
loadt2player(316)[ READ MORE ]
PHP – Tính Can Chi
Xác định 1 năm can chi là gì, cái này tớ chuyển từ C qua
Đây là hàm php đã chuyển:
<?php
function canchi($nam)
{
$acan = array("Giap", "At", "Binh", "Dinh", "Mau", "Ky", "Canh", "Tan", "Nham", "Quy");
$achi = array("Ty", "Suu", "Dan", "Meo", "Thin", "Ty", "Ngo", "Mao", "Than", "Dau", "Tuat", "Hoi");
$can = $acan[($nam+6)%10];
$chi = $achi[($nam+8)%12];
return $can." ".$chi;
}
echo canchi(1988);
?>
Còn đây là [ READ MORE ]
Morse Code encoder/decoder
Morse Code encoder/decoder
$lettertomorse=array(
"a" => ".-",
"b" => "-...",
"c" => "-.-.",
"d" => "-..",
"e" => ".",
"f" => "..-.",
"g" => "--.",
"h" => "....",
"i" => "..",
"j" => ".---",
"k" => ".-.",
"l" => ".-..",
"m" => "--",
"n" => "-.",
"o" => "---",
"p" => ".--.",
"q" => "--.-",
"r" => ".-.",
"s" => "...",
"t" => "-",
"u" => "..-",
"v" => "...-",
"w" => ".--",
"x" => "-..-",
"y" => "-.--",
"z" => "--..",
"1" [ READ MORE ]
Chuyển số thành số La Mã
Chuyển số thành số La Mã.
Chắc mọi người đều biết về số la mã: I, II, III, IV, V, VI, VII, VIII, IX, X….
Và…
M = 1,000
C = 100
X = 10
I = 1
D = 500
L = 50
V = 5
Đây là hàm chuyển số thành số La Mã:
// A function [ READ MORE ]
Login and Logout using Sessions and Cookies
Login and Logout using Sessions and Cookies.
1. Tại file functions.php với nội dung:
<?php
function createsessions($username,$password)
{
//Add additional member to Session array as per requirement
session_register();
$_SESSION["gdusername"] = $username;
$_SESSION["gdpassword"] = md5($password);
if(isset($_POST['remme']))
{
//Add additional member to cookie array as per requirement
setcookie("gdusername", $_SESSION['gdusername'], time()+60*60*24*100, "/");
setcookie("gdpassword", $_SESSION['gdpassword'], time()+60*60*24*100, "/");
return;
}
}
function clearsessionscookies()
{
unset($_SESSION['gdusername']);
unset($_SESSION['gdpassword']);
session_unset();
session_destroy();
setcookie ("gdusername", "",time()-60*60*24*100, "/");
setcookie ("gdpassword", "",time()-60*60*24*100, "/");
}
function confirmUser($username,$password)
{
// $md5pass = md5($password); // Not needed any [ READ MORE ]