C# Sharp Exercises: Display the pattern in which the first and a last number of each row will be 1
C# Sharp For Loop: Exercise-36 with Solution
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.
The pattern is as follows :
1 121 12321
Pictorial Presentation:
Sample Solution:
C# Sharp Code:
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");
}
}
}
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
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C# Sharp to display the first n terms of Fibonacci series.
Next: Write a program in C# Sharp to display the number in reverse order.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework