PDA

View Full Version : سوال: حل مثلث خیام در سی شارپ



amir eghbal
یک شنبه 06 اردیبهشت 1394, 11:40 صبح
با سلام
کسی میدونه چطوری میشه برنامه ای نوشت که مثلث خیام رو تا شیش سطر حل کنه.
ممنون

MehdiElexal
یک شنبه 06 اردیبهشت 1394, 12:10 عصر
با سلام این کد تا 100 سطر هم جواب میده

using System;
using System.Collections.Generic;
using System.Text;

namespace PascalTriangle
{
class PascalTriangle
{
static void Main(string[] args)
{

System.Console.WriteLine("Pascal Triangle Program");
System.Console.Write("Enter the number of rows: ");
string input = System.Console.ReadLine();

int n = Convert.ToInt32(input);


for (int y = 0; y < n; y++)
{
int c = 1;
for (int q = 0; q < n - y; q++)
{
System.Console.Write(" ");
}

for (int x = 0; x <= y; x++)
{
System.Console.Write(" {0:D} ", c);
c = c * (y - x) / (x + 1);
}
System.Console.WriteLine();
System.Console.WriteLine();
}
System.Console.WriteLine();
}
}
}



موفق باشید

MehdiElexal
یک شنبه 06 اردیبهشت 1394, 12:52 عصر
130637
اینم Windows Application با همون کد
موفق باشید

amir eghbal
یک شنبه 06 اردیبهشت 1394, 12:52 عصر
خیلی ممنونم ولی اگه میشه لطف کنید این برنامه رو تو محیط فرم برام بنویسید ممنون میشم

MehdiElexal
یک شنبه 06 اردیبهشت 1394, 13:14 عصر
بالاتر گذاشتم مهندس

marzieusefi
شنبه 30 آذر 1398, 19:16 عصر
ولی این کدا توی فرم نیست اجرا نمیشه کدای فرم رو بزارید