Write a program in C# Sharp to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to display the such a pattern for n number of rows using a number which will start with the number 1 and the first and a last number of each row will be 1

 1
 121
12321

Sample Output:

 Display the pattern in which first and last number of each row will be 1:                                  
----------------------------------------------------------------------------                                
Input number of rows : 5                                                                                    
    1                                                                                                       
   121                                                                                                      
  12321                                                                                                     
 1234321                                                                                                    
123454321

الأجوبة

using System;  
public class Exercise36  
{  
    public static void Main()
{
   int i,j,n;
   
	Console.Write("\n\n");
    Console.Write(" Display the pattern in which first and last number of each row will be 1:\n");
    Console.Write("----------------------------------------------------------------------------");
    Console.Write("\n\n");     
   
   Console.Write("Input number of rows : ");
   n = Convert.ToInt32(Console.ReadLine());    
   for(i=0;i<=n;i++)
   {
     /* print blank spaces */
     for(j=1;j<=n-i;j++)
	Console.Write(" ");
     /* Display number in ascending order upto middle*/
     for(j=1;j<=i;j++)
       Console.Write("{0}",j);
 
     /* Display  number in reverse order after middle */
       for(j=i-1;j>=1;j--)
	  Console.Write("{0}",j);
 
     Console.Write("\n");
   }
  } 
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...