Anda di halaman 1dari 41

http://cprogrammingcodes.blogspot.in/p/pyramid.

html
Qn 1
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
Console.Write("@");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 2
#####
####
###
##
#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i,j,k,n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("\nPattern is: \n");


for (i = 0; i < n; i++)
{
for (j = 0; j < i; j++)
Console.Write(" ");
for (k = n; k >= i; k--)
Console.Write("#");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 3
@@@@@
@@@@
@@@
@@
@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1 ; i--)
{
for (j = 0; j < i; j++)
Console.Write("@");
Console.Write("\n");
}
Console.ReadLine();
}
}
}

Qn 4
#
##
###
####
#####
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
Console.Write("#");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 5
@
@@
@@@
@@@@
@@@@@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n, temp;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
temp = n;
Console.WriteLine("\nPattern is: \n");
for (i = 0; i < n; i++)
{
for (j = 1; j < temp; j++)
Console.Write(" ");
temp--;
for (k = 0; k <= i; k++)
Console.Write("@");
Console.Write("\n");
}

Console.ReadLine();
}
}
}
Qn 6
12345
12345
12345
12345
12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 7
54321
54321
54321
54321
54321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{

int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = n; j >= 1; j--)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 8
55555
44444
33333
22222
11111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (j = n; j >= 1; j--)
Console.Write("{0}",i);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 9
11111
22222
33333
44444
55555
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = n; j >= 1; j--)
Console.Write("{0}",i);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 10
1
12
123
1234
12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}

Qn 11
12345
1234
123
12
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 12
1
12
123
1234
12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n, temp;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
temp = n;
Console.WriteLine("\nPattern is: \n");

for (i = 1; i <= n; i++)


{
for (j = 1; j < temp; j++)
Console.Write(" ");
temp--;
for (k = 1; k <= i; k++)
Console.Write("{0}",k);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 13
54321
4321
321
21
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
Console.Write("{0}",(j+1)-i);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 14
1
21
321
4321
54321
using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write("{0}", (i + 1) - j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 15
12345
1234
123
12
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (j = 1; j <= i; j++)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 16

12345
1234
123
12
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (j = n; j > i; j--)
Console.Write(" ");
for (k = 1; k <= i; k++)
Console.Write("{0}",k);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 17
1
121
12321
1234321
123454321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");

for (i = 1; i <= n; i++)


{
for (k = 1; k <= (n - i); k++)
Console.Write(" ");
for (j = 1; j <= i; j++)
Console.Write("{0}", j);
for (k = j - 2; k >= 1; k--)
Console.Write("{0}", k);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 18
123454321
1234321
12321
121
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (k = 1; k <= (n - i); k++)
Console.Write(" ");
for (j = 1; j <= i; j++)
Console.Write("{0}", j);
for (k = j - 2; k >= 1; k--)
Console.Write("{0}", k);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 19
*
***
*****

*******
*********
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (k = 1; k <= (n - i); k++)
Console.Write(" ");
for (j = 1; j <= (2*i - 1); j++)
Console.Write("*");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 20
1
23
456
7 8 9 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, a = 1;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{

Console.Write("{0}", a);
Console.Write(" ");
a++;
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 21

using System;
using System.Collections.Generic;
using System.Text;
namespace PascalTriangle
{
class PascalTriangle
{
static void Main(string[] args)
{
Console.Write("Enter the number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("\nPascal's Triangle is : \n\n");
for (int y = 0; y < n; y++)
{
int c = 1;
for (int q = 0; q < n - y; q++)
Console.Write(" ");
for (int x = 0; x <= y; x++)
{
Console.Write(" {0} ", c);
c = c * (y - x) / (x + 1);
}
Console.WriteLine();
Console.WriteLine();
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Qn 22
A
BB
CCC
DDDD
E E E E E

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
char ch = 'A';
int n = Convert.ToInt32 (ch);
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
char ch1 = Convert.ToChar(n);
Console.Write("{0}", ch1);
Console.Write(" ");
}
n++;
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 23
A
AB A
AB C BA
AB C D C B A
AB CDEDCBA
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++,n1++)

{
ch = (char)n1;
Console.Write("{0}", ch);
}
n1 = n1 - 2;
for (j = 1; j <= (i - 1); j++, n1--)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 24
ABCDEDCBA
BCDEDCB
CDEDC
DED
E
Qn 25
1
22
333
4444
55555
4444
333
22
1
using System;
using System.Collections.Generic;
using System.Text;
namespace PascalTriangle
{
class PascalTriangle
{
static void Main(string[] args)
{
Console.Write("Enter the number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("\nPattern is : \n");
int i, j, k;
for (i = 1; i <= n; i++)
{
for (j = 0; j < i; j++)
Console.Write("{0}", i);
Console.Write("\n");
}
for (k = (n-1); k >= 1; k--)
{

for (j = 0; j < k; j++)


Console.Write("{0}", k);
Console.Write("\n");
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Qn 26
I
IN
IND
INDI
INDIA
INDI
IND
IN
I
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
string ch = "INDIA";
int len = ch.Length;
Console.WriteLine("Pattern is: \n");
for (int i = 0; i < len; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write("{0}", ch[j]);
}
Console.Write("\n");
}
for (int i = (len-1); i > 0; i--)
{
for (int j = 0; j < i; j++)
{
Console.Write("{0}", ch[j]);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}

Qn 27
A
BB
CCC
DDDD
CCC
BB
A
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
char ch = 'A';
int n = Convert.ToInt32(ch);
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= i; j++)
{
char ch1 = Convert.ToChar(n);
Console.Write("{0}", ch1);
Console.Write(" ");
}
n++;
Console.Write("\n");
}
for (int i = 3; i >= 1; i--)
{
char ch2 = 'C';
int n1 = Convert.ToInt32(ch2);
for(int k = 1; k <= i; k++)
{
char ch3 = Convert.ToChar(n1);
Console.Write("{0}", ch3);
Console.Write(" ");
}
n1--;
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 28
1
22
333

4444
55555
using System;
using System.Collections.Generic;
using System.Text;
namespace PascalTriangle
{
class PascalTriangle
{
static void Main(string[] args)
{
Console.Write("Enter the number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("\nPattern is : \n");
int i, j;
for (i = 1; i <= n; i++)
{
for (j = 0; j < i; j++)
Console.Write("{0}", i);
Console.Write("\n");
}
Console.WriteLine();
Console.ReadLine();
}
}
}
Qn 29
123454321
2345432
34543
454
5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
{
if (i > j)
Console.Write(" ");
else
Console.Write("{0}", j);

}
for (k = n - 1; k >= i; k--)
{
Console.Write("{0}", k);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 30
1
21
321
4321
54321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (k = 1; k <= (n - i); k++)
Console.Write(" ");
for (j = 1; j <= i; j++)
Console.Write("{0}", (i+1)-j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 31
54321
4321
321
21
1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = n; i >= 1; i--)
{
for (k = 1; k <= (n - i); k++)
Console.Write(" ");
for (j = 1; j <= i; j++)
Console.Write("{0}", (i+1)-j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 32
1
22
333
4444
55555
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++)
{

Console.Write("{0}", i);
Console.Write(" ");
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 33
1
12
123
1234
12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++)
{
Console.Write("{0}", k);
Console.Write(" ");
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 34
*
***
*****
*******
*****
***
*

Qn 35
1
212
32123
4321234
32123
212
1
Qn 36
1
121
12321
1234321
12321
121
1
Qn 37
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
n1 = n1 - 2;
for (j = 1; j <= (i - 1); j++, n1--)
{

ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
for (i = n-1; i >= 1; i--)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
n1 = n1 - 2;
for (j = 1; j <= (i - 1); j++, n1--)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 38
A
ABA
ABCBA
ABCDCBA
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{

ch = (char)n1;
Console.Write("{0}", ch);
}
n1 = n1 - 2;
for (j = 1; j <= (i - 1); j++, n1--)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n");
for (i = n; i >= 1; i--)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
n1 = n1 - 2;
for (j = 1; j <= (i - 1); j++, n1--)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 40

A
AB
ABC
ABCD
ABCDE
ABCD
ABC
AB
A
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
for (i = n-1; i >= 1; i--)
{
char ch = 'A';
int n1 = (int)ch;
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (k = 1; k <= i; k++, n1++)
{
ch = (char)n1;
Console.Write("{0}", ch);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 41

A
BA
CBA
DCBA
EDCBA
DCBA
CBA
BA
A
Qn 42
EDCBA
DCBA
CBA
BA
A
Qn 43
9
01
234
5678
90123
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, m = 9;
Console.WriteLine("Pattern is: \n");
for (i = 1; i <= 5; i++)
{
for (j = 1; j <= i; j++, m = m % 10)
{
Console.Write("{0}", m);
Console.Write(" ");
m++;
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 44
12344321
123__321

12____21
1______1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, c, n;
Console.WriteLine("Enter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
c = n + 1;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
if (j >= c)
Console.Write("_");
else
Console.Write("{0}", j);
for (k = n; k >= 1; k--)
if (k >= c)
Console.Write("_");
else
Console.Write("{0}",k);
Console.Write("\n");
c--;
}
Console.ReadLine();
}
}
}
Qn 55
*
***
******
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)

{
int i, j, n;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= (2 * i - 1); j++)
Console.Write("*");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 56
**********
**** ****
***
***
**
**
*
*
Qn 57
1
3 5 7
9 11 13 15 17 19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("Enter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
if (n % 2 == 0)
{
Console.WriteLine("\nMust enter some odd number");
Console.ReadLine();
}
else
{
Console.WriteLine("\nPattern is: \n");
Console.WriteLine("1");
int z = n;
for (i = 1; i < n; i++)
{
for (j = 1; j <= 3 * i; j++, z = z + 2)
Console.Write("{0} ", z);
Console.Write("\n");

}
}
Console.ReadLine();
}
}
}
Qn 58
54321
5432
543
54
5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("Enter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = n; j >= i; j--)
Console.Write("{0}",j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 59
1
AB
123
ABCD
12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{

class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n\n");
for (i = 1; i <= n; i++)
{
char ch = 'A', ch1 = 'A';
int con = Convert.ToInt32(ch);
for (j = 1; j <= i; j++)
if (i % 2 == 0)
{
Console.Write("{0}", ch1);
con++;
ch1 = Convert.ToChar(con);
}
else
Console.Write("{0}", j);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 60
1
23
456
7 8 9 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n, temp=1;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= (n - i); j++)
Console.Write(" ");
for (int k = 1; k <= i; k++)
Console.Write("{0} ", temp++);

Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 61
12345
2345
345
45
5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write(" ");
for (int k = i; k <= n; k++)
Console.Write("{0} ",k);
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 62
A
BA
ABA
BABA
ABABA
Qn 63
*
**

***
****
***
**
*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("Enter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write("*");
Console.Write("\n");
}
for (i = n - 1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
Console.Write("*");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 75
1
a
21 ba
321 cba
4321 dcba
54321 edcba
Qn 76
1
01
010
1010
10101
Qn 77

1
01
101
0101
10101
Qn 78
*****
*
*

*
*

*****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, r, n;
Console.WriteLine("\nEnter number of stars u want: ");
n = Convert.ToInt32(Console.ReadLine()); //cols
Console.WriteLine("\nEnter number of lines: ");
int m = Convert.ToInt32(Console.ReadLine()); //rows
Console.WriteLine("\nPattern is: \n");
Console.Write(" ");
for (r = 1; r <= n; r++)
Console.Write("*");
Console.Write("\n");
for (i = 1; i <= m - 2; i++)
{
Console.Write("*");
Console.Write(" ");
for (int temp = 1; temp <= n+1; temp++)
Console.Write(" ");
Console.Write("*\n");
}
Console.Write(" ");
for (r = 1; r <= n; r++)
Console.Write("*");
Console.ReadLine();
}
}
}

Qn 79
******
*
*
*
*
******
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, r, n;
Console.WriteLine("\nEnter number of stars u want: ");
n = Convert.ToInt32(Console.ReadLine()); //cols
Console.WriteLine("\nEnter number of lines: ");
int m = Convert.ToInt32(Console.ReadLine()); //rows
Console.WriteLine("\nPattern is: \n");
for (r = 1; r <= n; r++)
Console.Write("*");
Console.Write("\n");
for(i = 1; i<= m-2; i++)
{
Console.Write("*");
for(int temp = 1; temp <= n-2; temp++)
Console.Write(" ");
Console.Write("*\n");
}
for(r = 1; r <= n; r++)
Console.Write("*");
Console.ReadLine();
}
}
}
Qn 80
*
1*
*2
1*3*
*2*4
1*3*5*
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of lines: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
Console.Write("*\n");
for (i = 1; i <= n; i++)
if (i % 2 != 0)
{
for (j = 1; j <= i; j=j+2)
{
Console.Write("{0}", j);
Console.Write("*");
}
Console.WriteLine();
}
else
{
for (j = 2; j <= i; j = j + 2)
{
Console.Write("*");
Console.Write("{0}", j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
Qn 81
1
AB
234
CDEF
56789
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{

static void Main(string[] args)


{
int i, j, n, temp = 1;
Console.WriteLine("\nEnter number of rows: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Pattern is: \n\n");
char ch = 'A', ch1 = 'A';
int con = Convert.ToInt32(ch);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
if (i % 2 == 0)
{
Console.Write("{0} \t",ch1);
con++;
ch1 = Convert.ToChar(con);
}
else
Console.Write("{0} \t", temp++);
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 82
* *** *** *
** ** ** **
*** * * ***
Qn 83
4572
572
72
2
Qn 84
1
23
4
56
7
89
10
Qn 85
1
121
1231
12341
123451

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write("{0}", j);
if (i != 1)
Console.Write("1");
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 86
1
121
12321
1234321
123454321
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n;
Console.WriteLine("\nEnter number of rows: \n");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
Console.Write("{0}", j);
for (k = j - 2; k >= 1; k--)
Console.Write("{0}", k);
Console.Write("\n");

}
Console.ReadLine();
}
}
}
Qn 87
1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\nEnter number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: ");
Console.Write("1");
for (int i = 1; i <= n; i++)
{
for (int j = 2; j <= i; j++)
{
Console.Write("{0}", i);
Console.Write("*");
}
if (i != 1)
{
Console.Write("{0}", i);
}
Console.Write("\n");
}
for (int i = n; i >= 1; i--)
{
for (int j = 2; j <= i; j++)
{
Console.Write("{0}", i);
Console.Write("*");
}
Console.Write("{0}", i);
Console.Write("\n");
}
Console.ReadLine();
}
}

}
Qn 93
9
10 8
9 7 5
6 4 2 0
1 -1 -3 -5 -7
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, temp=9;
for (i = 1; i <= 5; i++,temp=temp+3)
{
for(j=1;j<=i;j++, temp = temp - 2)
Console.Write("{0} \t", temp);
Console.WriteLine("");
}
Console.Read();
}
}
}
Qn 94
*000*000*
0*00*00*0
00*0*0*00
000***000
Qn 95
1
2 7
3 8 13
4 9 14 19
5 10 15 20 25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)

{
Console.WriteLine("\nEnter number of rows: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: ");
for (int i = 1; i <= n; i++)
{
Console.Write("{0} ", i);
int temp = i;
for (int j = 2; j <= i; j++)
{
Console.Write("{0} ", temp+5);
temp = temp + 5;
}
Console.Write("\n");
}
Console.ReadLine();
}
}
}
Qn 96
A
1
BB
22
CCC
333
Qn 97
@
#
@@
##
@@@
###
Qn 98
1
149
1 4 9 16 25
1 4 9 16 25 36 49
1 4 9 16 25 36 49 64 81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int i, j, n;

Console.WriteLine("Enter number of rows: ");


n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nPattern is: \n");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= (2*i-1); j++)
Console.Write("{0} ",(j*j));
Console.Write("\n");
}
Console.ReadLine();
}
}
}

Anda mungkin juga menyukai