3. محاسبه ی عدد پی
زبان نوشتای Ruby
سطح برنامه : آسان
*********//*********
num = 4.0
pi = 0
plus = true
den = 1
while den < 10000000
if plus
pi = pi + num/den
plus = false
else
pi = pi - num/den
plus = true
end
den = den + 2
end
puts "PI = #{pi}" # calculated value of pi
puts "Math::PI = #{Math::PI}" # pi from the math class
@de_coder
زبان نوشتای Ruby
سطح برنامه : آسان
*********//*********
num = 4.0
pi = 0
plus = true
den = 1
while den < 10000000
if plus
pi = pi + num/den
plus = false
else
pi = pi - num/den
plus = true
end
den = den + 2
end
puts "PI = #{pi}" # calculated value of pi
puts "Math::PI = #{Math::PI}" # pi from the math class
@de_coder
4. مرتب سازی Insertion sort
زبان نوشتاری JAVA
سطح سوال : آسان
*********//*********
public class Main
{
public static void main(String[] args)
{
System.out.println(" The Number Before sorting :");
int[] ay = {
5,6,7,3,5,7,8,8,6,4,2,6,8,6,3,2,6,6,8,8,4,3,6,8,
5,4,3,2,1,6,4,2,4,6,7,7,9,7,5,4,6,7,9,7,5,3,3,46,7,8,9,6,5,3,4,6,7,7,8,9,5,6,4,3,5,7,7
,5,6,7,3,2,5,6,3,6,4,6,5,4,3,35,5,5,2,5,3,4,66,3,5,3,5,3,5,5,3,5,3,5,4,5,4,7,5,4,5,5,5,4,3,3,1,2,1
};
print(ay);
System.out.println("\n\n\n");
int[] l = insertionsrt(ay);
System.out.println("After sorting with Insertion Sort :");
print(l);
System.out.println("\n\n\n");
}
static int c = 0;
public static void print(int[] arr){
if(c<arr.length){
System.out.print(arr[c++]+",");
print(arr);
}
else{
c=0;
return;
}}
private static int[] sorter;
private static void swap(int post1,int post2){
int val1 = sorter[post1],
val2 = sorter[post2];
sorter[post1] = val2;
sorter[post2] = val1;
}
public static int[] insertionsrt(int[] arr){
sorter = arr;
int x1 = 0,
x2 = 0,
y1 = 0,
y2 = 0,
idx = sorter.length-1,
post1 = 0;
boolean done = true;
while(done) {
if(x1 <idx){
x2 = x1+1;
if(x1 == 0 && x2 == 1){
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;
x1++;
}
else{
//TODO
if(post1 == 1){
//TODO
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;
}
else if(post1 == 2){
//TODO
y1 = x1;
y2 = y1-1;
while(y2 > -1)
{
if(sorter[y1] < sorter[y2]){
swap(y2,y1);
}
y2--;y1--;
}
post1--;
x1++;
}
//TODO
}
}
else done = false;
}
return sorter;
}
}
@de_coder
زبان نوشتاری JAVA
سطح سوال : آسان
*********//*********
public class Main
{
public static void main(String[] args)
{
System.out.println(" The Number Before sorting :");
int[] ay = {
5,6,7,3,5,7,8,8,6,4,2,6,8,6,3,2,6,6,8,8,4,3,6,8,
5,4,3,2,1,6,4,2,4,6,7,7,9,7,5,4,6,7,9,7,5,3,3,46,7,8,9,6,5,3,4,6,7,7,8,9,5,6,4,3,5,7,7
,5,6,7,3,2,5,6,3,6,4,6,5,4,3,35,5,5,2,5,3,4,66,3,5,3,5,3,5,5,3,5,3,5,4,5,4,7,5,4,5,5,5,4,3,3,1,2,1
};
print(ay);
System.out.println("\n\n\n");
int[] l = insertionsrt(ay);
System.out.println("After sorting with Insertion Sort :");
print(l);
System.out.println("\n\n\n");
}
static int c = 0;
public static void print(int[] arr){
if(c<arr.length){
System.out.print(arr[c++]+",");
print(arr);
}
else{
c=0;
return;
}}
private static int[] sorter;
private static void swap(int post1,int post2){
int val1 = sorter[post1],
val2 = sorter[post2];
sorter[post1] = val2;
sorter[post2] = val1;
}
public static int[] insertionsrt(int[] arr){
sorter = arr;
int x1 = 0,
x2 = 0,
y1 = 0,
y2 = 0,
idx = sorter.length-1,
post1 = 0;
boolean done = true;
while(done) {
if(x1 <idx){
x2 = x1+1;
if(x1 == 0 && x2 == 1){
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;
x1++;
}
else{
//TODO
if(post1 == 1){
//TODO
if(sorter[x2]<sorter[x1])swap(x1,x2);
post1++;
}
else if(post1 == 2){
//TODO
y1 = x1;
y2 = y1-1;
while(y2 > -1)
{
if(sorter[y1] < sorter[y2]){
swap(y2,y1);
}
y2--;y1--;
}
post1--;
x1++;
}
//TODO
}
}
else done = false;
}
return sorter;
}
}
@de_coder
5. ساخت تقویم
زبان نوشتاری PHP
سطح برنامه : متوسط
*********//*********
<style>
calendar { border-left:1px solid #999; width:100%;}
* html .day, * html .day-np { height:80px;}
.day:hover { background:#eceff5; }
.day-np { background:#ccc; min-height:80px; }
.day-head { background:#17a68a; color:#fff; font-weight:bold; text-align:center; padding:5px; width:80px; border-top:1px solid #636363; border-right:1px solid #636363; }
.day-num { background:#353632; padding:5px; color:#fff; font-weight:bold; float:right; margin:-5px -5px 0 0; width:20px; text-align:center; }
.day, .day-np { padding:5px; border-bottom:1px solid #636363; width:80px; border-right:1px solid #636363; }
.day { color:#353632; font-weight:bold; }
</style>
<?php
function draw_calendar($month, $year) {
$cal = '<table cellpadding="0" cellspacing="0" class="calendar" width="100%">';
$headings = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$cal .= '<tr class="row">
<td class="day-head">'
.implode('</td><td class="day-head">',$headings).'
</td></tr>';
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
$cal .= '<tr class="row">';
for($x = 0; $x < $running_day; $x++) {
$cal .= '<td class="day-np"> </td>';
$days_in_this_week++;
}
for($list_day = 1; $list_day <= $days_in_month; $list_day++) {
$cal .= '<td class="day" align="center">';
$cal .= $list_day;
$cal .= str_repeat('<p> </p>', 2);
$cal.= '</td>';
if($running_day == 6) {
$cal .= '</tr>';
if(($day_counter+1) != $days_in_month) {
$cal .= '<tr class="row">';
}
$running_day = -1;
$days_in_this_week = 0;
}
$days_in_this_week++;
$running_day++;
$day_counter++;
};
if($days_in_this_week < 8) {
for($x = 1; $x <= (8 - $days_in_this_week); $x++) {
$cal .= '<td class="day-np"> </td>';
}
}
$cal .= '</tr>';
$cal .= '</table>';
return $cal;
}
//Draw calendar for the current month/year
echo draw_calendar(date("m"), date("Y"));
?>
@de_coder
زبان نوشتاری PHP
سطح برنامه : متوسط
*********//*********
<style>
calendar { border-left:1px solid #999; width:100%;}
* html .day, * html .day-np { height:80px;}
.day:hover { background:#eceff5; }
.day-np { background:#ccc; min-height:80px; }
.day-head { background:#17a68a; color:#fff; font-weight:bold; text-align:center; padding:5px; width:80px; border-top:1px solid #636363; border-right:1px solid #636363; }
.day-num { background:#353632; padding:5px; color:#fff; font-weight:bold; float:right; margin:-5px -5px 0 0; width:20px; text-align:center; }
.day, .day-np { padding:5px; border-bottom:1px solid #636363; width:80px; border-right:1px solid #636363; }
.day { color:#353632; font-weight:bold; }
</style>
<?php
function draw_calendar($month, $year) {
$cal = '<table cellpadding="0" cellspacing="0" class="calendar" width="100%">';
$headings = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
$cal .= '<tr class="row">
<td class="day-head">'
.implode('</td><td class="day-head">',$headings).'
</td></tr>';
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
$cal .= '<tr class="row">';
for($x = 0; $x < $running_day; $x++) {
$cal .= '<td class="day-np"> </td>';
$days_in_this_week++;
}
for($list_day = 1; $list_day <= $days_in_month; $list_day++) {
$cal .= '<td class="day" align="center">';
$cal .= $list_day;
$cal .= str_repeat('<p> </p>', 2);
$cal.= '</td>';
if($running_day == 6) {
$cal .= '</tr>';
if(($day_counter+1) != $days_in_month) {
$cal .= '<tr class="row">';
}
$running_day = -1;
$days_in_this_week = 0;
}
$days_in_this_week++;
$running_day++;
$day_counter++;
};
if($days_in_this_week < 8) {
for($x = 1; $x <= (8 - $days_in_this_week); $x++) {
$cal .= '<td class="day-np"> </td>';
}
}
$cal .= '</tr>';
$cal .= '</table>';
return $cal;
}
//Draw calendar for the current month/year
echo draw_calendar(date("m"), date("Y"));
?>
@de_coder
7. ساخت یک نبرد اتوماتیک
زبان نوشتاری #C
سطح برنامه : متوسط رو به بالا
*********//*********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace de_coder
{
class Program
{
static void Main(string[] args)
{
int herohealth;
int monsterhealth;
string monstername;
int monsterhealthbegining;
Random healthgen = new Random();
herohealth = healthgen.Next(5, 21);
Console.WriteLine("you have " + herohealth + " health");
monsterhealth = healthgen.Next(5, 21);
monsterhealthbegining = monsterhealth;
if (monsterhealth <= 8)
{
monstername = "goblin";
Console.WriteLine("A simple goblin with " + monsterhealth + " health attacks!");
goto heroattack;
}
else if (monsterhealth >= 9 && 13 >= monsterhealth )
{
monstername = "owlbear";
Console.WriteLine("An owlbear with " + monsterhealth + " health attacks!");
goto heroattack;
}
else if (monsterhealth >= 14 && 17 >= monsterhealth)
{
monstername = "orc";
Console.WriteLine("An orc with " + monsterhealth + " health attacks!");
goto heroattack;
}
else
{
monstername = "dragon";
Console.WriteLine("A dragon with " + monsterhealth + " health attacks!");
goto heroattack;
}
heroattack:
System.Threading.Thread.Sleep(50);
if (herohealth >= 0)
{
Random roll = new Random();
int roll20;
int roll6;
int damage;
roll20 = roll.Next(1, 21);
if (roll20 >= 9)
{
Console.Write("You hit it for ");
roll6 = roll.Next(1, 7);
Console.WriteLine(roll6 + " damage!");
damage = roll6;
monsterhealth -= damage;
if (monsterhealth >= 0)
{
goto monsterattack;
}
else
{
Console.WriteLine("You win!");
}
}
else
{
Console.WriteLine("You missed!");
goto monsterattack;
}
}
else
{
Console.WriteLine("You loose!");
}
monsterattack:
System.Threading.Thread.Sleep(50);
if (monsterhealth >= 0)
{
Random roll = new Random();
int roll202;
int roll62;
int damage2;
roll202 = roll.Next(1, 21);
if (roll202 >= 9)
{
Console.Write("It hits you for ");
roll62 = roll.Next(1, 7);
Console.WriteLine(roll62 + " damage!");
damage2 = roll62;
herohealth -= damage2;
if (herohealth >= 0)
{
goto heroattack;
}
else
{
Console.WriteLine("You loose!");
}
}
else
{
Console.WriteLine("It missed!");
goto heroattack;
}
}
else
{
int reward;
reward = monsterhealthbegining * 10;
Console.WriteLine("You got " + reward + " silver for slaying the " + monstername + ".");
}
}
}
}
@de_coder
زبان نوشتاری #C
سطح برنامه : متوسط رو به بالا
*********//*********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace de_coder
{
class Program
{
static void Main(string[] args)
{
int herohealth;
int monsterhealth;
string monstername;
int monsterhealthbegining;
Random healthgen = new Random();
herohealth = healthgen.Next(5, 21);
Console.WriteLine("you have " + herohealth + " health");
monsterhealth = healthgen.Next(5, 21);
monsterhealthbegining = monsterhealth;
if (monsterhealth <= 8)
{
monstername = "goblin";
Console.WriteLine("A simple goblin with " + monsterhealth + " health attacks!");
goto heroattack;
}
else if (monsterhealth >= 9 && 13 >= monsterhealth )
{
monstername = "owlbear";
Console.WriteLine("An owlbear with " + monsterhealth + " health attacks!");
goto heroattack;
}
else if (monsterhealth >= 14 && 17 >= monsterhealth)
{
monstername = "orc";
Console.WriteLine("An orc with " + monsterhealth + " health attacks!");
goto heroattack;
}
else
{
monstername = "dragon";
Console.WriteLine("A dragon with " + monsterhealth + " health attacks!");
goto heroattack;
}
heroattack:
System.Threading.Thread.Sleep(50);
if (herohealth >= 0)
{
Random roll = new Random();
int roll20;
int roll6;
int damage;
roll20 = roll.Next(1, 21);
if (roll20 >= 9)
{
Console.Write("You hit it for ");
roll6 = roll.Next(1, 7);
Console.WriteLine(roll6 + " damage!");
damage = roll6;
monsterhealth -= damage;
if (monsterhealth >= 0)
{
goto monsterattack;
}
else
{
Console.WriteLine("You win!");
}
}
else
{
Console.WriteLine("You missed!");
goto monsterattack;
}
}
else
{
Console.WriteLine("You loose!");
}
monsterattack:
System.Threading.Thread.Sleep(50);
if (monsterhealth >= 0)
{
Random roll = new Random();
int roll202;
int roll62;
int damage2;
roll202 = roll.Next(1, 21);
if (roll202 >= 9)
{
Console.Write("It hits you for ");
roll62 = roll.Next(1, 7);
Console.WriteLine(roll62 + " damage!");
damage2 = roll62;
herohealth -= damage2;
if (herohealth >= 0)
{
goto heroattack;
}
else
{
Console.WriteLine("You loose!");
}
}
else
{
Console.WriteLine("It missed!");
goto heroattack;
}
}
else
{
int reward;
reward = monsterhealthbegining * 10;
Console.WriteLine("You got " + reward + " silver for slaying the " + monstername + ".");
}
}
}
}
@de_coder
Forwarded from Deleted Account
کانالی درباره برنامه نویسی از هر زبانی ک فکرش را بکنید.
آموزش تمام زبان های برنامه نویسی دنیا
وبه همراه نمونه کار و خروجی برنامه.
ویژه رشته کامپیوتر.🆕
⬇️⬇️⬇️⬇️⬇️⬇️⬇️
DE.coder();
https://telegram.me/de_coder
آموزش تمام زبان های برنامه نویسی دنیا
وبه همراه نمونه کار و خروجی برنامه.
ویژه رشته کامپیوتر.🆕
⬇️⬇️⬇️⬇️⬇️⬇️⬇️
DE.coder();
https://telegram.me/de_coder