These program prints various different patterns of numbers and stars. These codes illustrate how to create various patterns using c programming. Most of these c programs involve usage of nested loops and space. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not. Please see the complete page and look at comments for many different patterns.
We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.
i want to print this format in c#
ReplyDelete* *
** **
*** ***
**** ****
**********
but it print this
*
**
***
****
*****
*
**
***
****
*****
i am writing this code:-
int number = 5;
int i, j, k;
for (i = 1; i <= number; i++)
{
for (j = 1; j <= number - i; j++)
{
Console.Write("");
}
for (k = 1; k <= i; k++)
{
Console.Write("*");
}
Console.WriteLine("");
}
for (i = 1; i <= number; i++)
{
for (j = 1; j <= number - i; j++)
{
Console.Write(" ");
}
for (k = 1; k <= i; k++)
{
Console.Write("*");
}
Console.WriteLine("");
}
Console.ReadLine();
class Program
Delete{
static void Main(string[] args)
{
string str = "*";
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.Write(" ");
for (int m = 1; m <= i; m++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
hi Ms Durga,
Deletei want to print lyk this
____a____
___bab___
__cbabc__
_dcbabcd_
edcbabcde
can u just hlp me out how do i print this in c# ?
Regards,
Hiren
This comment has been removed by the author.
DeleteThis comment has been removed by the author.
Deleteint num=5,x = 98,y;
Deletefor (int i = 1; i <= num; i++)
{
for (int j = 1; j <= (num - i); j++)
{
Console.Write("_");
}
y=x;
for (int k = 1; k <= i; k++)
{
y--;
Console.Write(Convert.ToChar(y));
}
for (int l = 1; l <= (i - 1); l++)
{
y++;
Console.Write(Convert.ToChar(y));
}
for (int m = 1; m <= (num - i); m++)
{
Console.Write("_");
}
x++;
Console.WriteLine();
}
Console.ReadLine();
This comment has been removed by the author.
ReplyDeleteTry this...
Deleteint num = 5;
for (int i = 1; i <= num; ++i)
{
for (int j = 1; j <= i; ++j)
{
Console.Write("*");
}
if (i != num - 1)
{
Console.Write(" ");
}
else
{
Console.Write(" * ");
}
for (int j = 1; j <= i; ++j)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.ReadLine();
This comment has been removed by the author.
ReplyDeletehi Ms Surani,
Deletei want to print lyk this
____a____
___bab___
__cbabc__
_dcbabcd_
edcbabcde
can u just hlp me out how do i print this in c# ?
Regards,
Hiren
hi Ms Surani,
Deletei want to print lyk this
____a____
___bab___
__cbabc__
_dcbabcd_
edcbabcde
can u just hlp me out how do i print this in c# ?
Regards,
Hiren
Nice examples
ReplyDeleteTry this
ReplyDeleteFor( int I=1; I<=10; I++)
{
For( int j=0; j<=I; j++ )
Console.write("*" )
Console.writeline(" ");
}
Console.readline();
I want to print:
ReplyDeleteA
A B
A B C
A B C D
How to do this?
class Program
Delete{
static void Main(string[] args)
{
string str = "ABCD";
int m=str.Length;
for (int i = 0; i < str.Length; i++)
{
for (int j = 0; j <= i; j++)
{
Console.Write(str[m-(m-j)]);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
is there any other solution for this related task.plse share it to kdrnlr@gmail.com
class Program
Delete{
static void Main(string[] args)
{
int num = 4, x = 65, y;
for (int i = 1; i <= num; i++)
{
y = x;
for (int j = 1; j <= i; j++)
{
Console.Write(Convert.ToChar(y));
y++;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
If i want to make the pyramid with the help of foreach loop then it is possible or not???
ReplyDeleteit's possible
Deletepooku
ReplyDeleteThank you So much Dude
ReplyDeletegd
ReplyDeletei want to print to like 1
ReplyDelete1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
how do this pls reply
have you got the code for that. If so, Please share with me at hassansafeer.sbi@gmail.com
Delete1
121
12321
1234321
123454321
1234321
12321
121
1
lyt leee
ReplyDeleteI Want program for this output...
ReplyDelete1
13
135
In C#
ReplyDeletei want to print a pattern using for and while loop in c# like this
ReplyDelete***S******
******S***
***S******
******S***
***S******
******S***
how to do it? help please =(
oye lun tjhy mil gay yeh pattern ???
DeleteI want Program for this output
Delete999999999
12345678
7777777
123456
55555
1234
333
12
1
using System;
Deleteclass pyramid {
static void Main() {
/** Pyramid stars Looking down
Comment this if u need only a upside pyramid **/
int row, i, j;
// Total number of rows
// You can get this as users input
//row = Int32.Parse(Console.ReadLine());
row = 5;
// To print odd number count stars use a temp variable
int temp;
temp = row;
// Number of rows to print
// The number of row here is 'row'
// You can change this as users input
for ( j = 1 ; j <= row ; j++ ) {
// Printing odd numbers of stars to get
// Number of stars that you want to print with respect to the value of "i"?
for ( i = 1 ; i <= 2*temp - 1 ; i++ )
Console.Write("*");
// New line after printing a row
Console.Write("\n");
for ( i = 1 ; i <= j ; i++ )
Console.Write(" ");
// Reduce temp value to reduce stars count
temp--;
}
/** Pyramid stars Looking up
Comment this if u need only a downside pyramid **/
int rowx, k, l;
// Total number of rows
// You can get this as users input
// rowx = Int32.Parse(Console.ReadLine());
rowx = 5;
// To print odd number count stars use a temp variable
int tempx;
tempx = rowx;
//Remove this if u use
Console.Write("\n");
// Number of rows to print
// The number of row here is 'rowx'
for ( l = 1 ; l <= rowx ; l++ ) {
// Leaving spaces with respect to row
for ( k = 1 ; k < tempx ; k++ )
Console.Write(" ");
// Reduce tempx value to reduce space(" ") count
tempx--;
// Printing stars
for ( k = 1 ; k <= 2*l - 1 ; k++ )
Console.Write("*");
// New line after printing a row
Console.Write("\n");
}
}
}
http://paidtorefer.org/Default.aspx?Refer=604913
ReplyDeletePlz tell me to logic of this code
ReplyDelete******
*****
****
***
**
*
using System;
Deleteclass pyramid {
static void Main() {
/** Pyramid stars Looking down
Comment this if u need only a upside pyramid **/
int row, i, j;
// Total number of rows
// You can get this as users input
//row = Int32.Parse(Console.ReadLine());
row = 5;
// To print odd number count stars use a temp variable
int temp;
temp = row;
// Number of rows to print
// The number of row here is 'row'
// You can change this as users input
for ( j = 1 ; j <= row ; j++ ) {
// Printing odd numbers of stars to get
// Number of stars that you want to print with respect to the value of "i"?
for ( i = 1 ; i <= 2*temp - 1 ; i++ )
Console.Write("*");
// New line after printing a row
Console.Write("\n");
for ( i = 1 ; i <= j ; i++ )
Console.Write(" ");
// Reduce temp value to reduce stars count
temp--;
}
/** Pyramid stars Looking up
Comment this if u need only a downside pyramid **/
int rowx, k, l;
// Total number of rows
// You can get this as users input
// rowx = Int32.Parse(Console.ReadLine());
rowx = 5;
// To print odd number count stars use a temp variable
int tempx;
tempx = rowx;
//Remove this if u use
Console.Write("\n");
// Number of rows to print
// The number of row here is 'rowx'
for ( l = 1 ; l <= rowx ; l++ ) {
// Leaving spaces with respect to row
for ( k = 1 ; k < tempx ; k++ )
Console.Write(" ");
// Reduce tempx value to reduce space(" ") count
tempx--;
// Printing stars
for ( k = 1 ; k <= 2*l - 1 ; k++ )
Console.Write("*");
// New line after printing a row
Console.Write("\n");
}
}
}
//32.================================================
Deleteusing System;
class program
{
public static void Main()
{
Console.WriteLine("Program for displaying Pattern of '*'.");
Console.Write("Enter the maximum number of '*': ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Here is the Pattern of Stars");
for (int i = 0; i <= n; i++)
{
for (int j = i; j <= n - 1; j++)
Console.Write("*");
Console.WriteLine();
}
Console.ReadLine();
}
}
Please help me execute this pattern in C# :( I am trying for 3 days :(
ReplyDelete1
121
12321
1234321
123454321
1234321
12321
121
1
Please help me execute this pattern in C# :( I am trying for 3 days :(
ReplyDelete1
121
12321
1234321
123454321
1234321
12321
121
1
Please E-mail me at hassansafeer.sbi@gmail.com
This comment has been removed by the author.
Deletefor java programmers use this code to get the above output-----
Deletepackage webdriver_project;
public class forloop {
public static void main(String[] args) {
int i;
int j;
int k;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++){
System.out.print(j);
}
for(k=i;k>1;k--){
System.out.print(k-1);
}
System.out.println("");
}
for(i=4;i>=1;i--){
for(j=1;j<=i;j++){
System.out.print(j);
}
for(k=i;k>1;k--){
System.out.print(k-1);
}
System.out.println("");
}
}
}
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI want to print :
ReplyDelete1
21
321
4321
Please reply me
using System;
Deleteusing System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArshLogicalProg
{
class Patternv
{
static void Main()
{
for (int i = 1; i <= 4; i++)
{
for (int j = i; j >= 1; j--)
{
Console.Write(j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
i want to print lyk this
ReplyDeletea
bab
cbabc
dcbabcd
edcbabcde
can u just hlp me out how do i print this in c#
1
ReplyDelete2 3
4 5 6
7 8 9 10
plz any one help to print this
using System;
Deleteusing System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArshLogicalProg
{
class Patternv
{
static void Main()
{
int a = 1;
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(a);
a++;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
1
Delete23
456
78910
i want to print this..
i want to print this
ReplyDelete1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
using System;
Deleteusing System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArshLogicalProg
{
class Patternv
{
static void Main()
{
for (int i = 1; i <= 4; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(i);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
in java------------
Deletepackage webdriver_project;
public class firstjavaclass {
public static void main(String[] args){
int i=1;
int j=1;
for(i=1;i<=5;i++){
for(j=1;j<=i;j++){
System.out.print(i);
}
System.out.println();
}
}}
Console.Write(" ");
ReplyDeletewhat does it mean???
hi, I want to print this this in c#.how i write?
ReplyDeleteIf user input is 2
Result is :
*
***
*****
* *
*** ***
***** *****
If user input is 3
Result is :
*
***
*****
* *
*** ***
***** *****
* * *
*** *** ***
***** ***** *****
If user input is 4
Result is :
*
***
*****
* *
*** ***
***** *****
* * *
*** *** ***
***** ***** *****
* * * *
*** *** *** ***
***** ***** ***** *****
1
ReplyDelete12
123
12
1
pls help me out for such type of program patern
Hi...could someone help me print this in c#...thanks
ReplyDelete1****
*2***
**3**
***4*
****5
can pls tell tis..
ReplyDelete*
##
***
####
11
ReplyDelete11 11
11 11 11
11 11 11 11
11 11 11 11 11
plz give me for this code in c#
Delete1 1
ReplyDelete2 3 2 3
4 5 6 4 5 6
7 8 9 10 9 8 7
This comment has been removed by the author.
ReplyDeleteankush this is the code you have to write for your program--
ReplyDeletepackage webdriver_project;
public class firstjavaclass {
public static void main(String[] args){
int i=1;
int j=1;
for(i=1;i<=5;i++){
System.out.println("");
for(j=1;j<=i;j++){
System.out.print("*");
}
System.out.print(" ");
for(j=i;j>=1;j--){
System.out.print("*");
}
}
}
}
having output---
* *
** **
*** ***
**** ****
***** *****
I want to print this patter
ReplyDelete*
*1*
*1*2*
*1*2*3* and so on please tell
3
ReplyDelete44
555
6666
6666
555
44
3
sir i want to print like this
ReplyDelete1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
This comment has been removed by the author.
Deleteusing System;
ReplyDeleteusing System.Collections.Generic;
using System.Text;
using sc=System.Console;
class Program
{
public static void Main()
{
Program o = new Program();
o.show();
Console.ReadKey();
}
void show ()
{
int p=1,v=1;
for (int i = 1; i <= 5; i++)
{
int c = v;
for (int j = 1; j <= i; j++)
sc.Write(c);
sc.WriteLine();
p = p + 1;
v = v + 1;
Console.WriteLine();
Console.WriteLine();
}
}
}
I was wondering how to make one like this for c#
ReplyDelete123454321
1234321
12321
121
1
This comment has been removed by the author.
ReplyDeletei have an array {1,2,3,4,5}
ReplyDeleteand blank space is *
then
i want to print
12345
*2345
**345
***45
****5
can any one tell me how can i do this?
Write a program that reads 3 numbers from users between 1 and 30 for each number that is read , your program should display the same number of adjacent asterisks . [ Using for loop ]
ReplyDeleteplease write program for this....
ReplyDelete5
456
34567
2345678
123456789
2345678
34567
456
5
using System;
Deleteclass Program
{
static void Main()
{
int num,start,temp,print;
num = start = temp = 5;
for (int i = 1; i <=(2*num-1); i++)
{
print = start;
for (int j = 1; ; j++)
{
Console.Write(print);
if (temp == print)
break;
print++;
}
Console.WriteLine();
if (i < num)
{
start--;
temp++;
}
else
{
start++;
temp--;
}
}
Console.ReadLine();
}
}
Please give me C# code for below (Diamond/Rhombus) output
ReplyDelete1
2 1 2
3 2 1 2 3
2 1 2
1
This comment has been removed by the author.
ReplyDeletei want this type of pattern
ReplyDelete1 2 3 4 5 6 7 8 9 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19
Hi
ReplyDeleteCan you answer This?
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Hi
ReplyDeleteCan you answer This?
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1