Simoh نشر 14 نوفمبر 2015 أرسل تقرير مشاركة نشر 14 نوفمبر 2015 أريد رسم مستطيل على console بلغة #C، وحقيقة أتضح لي أن الأمر صعب بعض الشيء لأنه يلزمني حسابات وبعض الأمور الرياضية لفعل ذلك، فهل أجد لديكم من توضيح حول الأمر؟ أو أي مساعدة على شكل كود برمجي؟ اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 E.Nourddine نشر 15 نوفمبر 2015 أرسل تقرير مشاركة نشر 15 نوفمبر 2015 إليك هذا المثال الذي استعنت به في أحد التطبيقات، هو بلغة #C وسينفعك :using System; public class Test { static int width; static int height; public static void Main() { Console.Write("Enter width of rectangle: "); width = int.Parse(Console.ReadLine()); Console.Write("Enter height of rectangle: "); height = int.Parse(Console.ReadLine()); Console.WriteLine(); if(width > 5 && width <= 80 && height > 5 && height <= 20) { draw(); } else { Console.WriteLine("Invalid entry!"); } } static void draw() { Console.WriteLine((float)width/(float)height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (IsBorder(x, y) || IsDiagonal(x, y)) { Console.Write("*"); } else { Console.Write(" "); } } Console.WriteLine(); } } static bool IsBorder(int x, int y) { return x == 0 || y == 0 || x == width - 1 || y == height - 1; } static bool IsDiagonal(int x, int y) { return width < height ? IsDiagonalHigh(x, y) : IsDiagonalWide(x,y); } static bool IsDiagonalHigh(int x, int y) { var aspectRatio = (float)width / (float)height; return x == (int)(y * aspectRatio) || x == width - (int)(y * aspectRatio) - 1; } static bool IsDiagonalWide(int x, int y) { var aspectRatio = (float)height / (float)width; return y == (int)(x * aspectRatio) || y == (int)((width - x - 1) * aspectRatio); } } اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
السؤال
Simoh
أريد رسم مستطيل على console بلغة #C، وحقيقة أتضح لي أن الأمر صعب بعض الشيء لأنه يلزمني حسابات وبعض الأمور الرياضية لفعل ذلك، فهل أجد لديكم من توضيح حول الأمر؟ أو أي مساعدة على شكل كود برمجي؟
رابط هذا التعليق
شارك على الشبكات الإجتماعية
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.