Ask Experts Questions for FREE Help !
Ask
    damaxy's Avatar
    damaxy Posts: 6, Reputation: 1
    New Member
     
    #1

    Apr 10, 2010, 07:21 AM
    How to print binary numbers triangle in c sharp??
    I am trying to write a C sharp program to display something like this
    1
    01
    101
    0101
    But I'm having trouble doing that.So far I can display only like this
    1
    10
    101
    1010
    I know its simple for you guys.. I need help... anyone?? Thanks in advance...
    damaxy's Avatar
    damaxy Posts: 6, Reputation: 1
    New Member
     
    #2

    Apr 10, 2010, 07:24 AM

    oh! My programs code is as the following:
    static void Main(string[] args)
    {
    String input;
    int I, j, ran;
    Console.WriteLine("Enter the Range:");
    input = Console.ReadLine();
    ran = Convert.ToInt16(input);

    for (I = 1; I <= ran; I++)
    {
    for (j = 1; j <= I; j++)
    {
    if (j % 2 == 0)
    {
    Console.Write("0 ");
    }
    else
    {
    Console.Write("1 ");
    }
    }
    Console.WriteLine();
    }
    Console.Read();
    }
    ashif's Avatar
    ashif Posts: 1, Reputation: 1
    New Member
     
    #3

    Feb 5, 2011, 11:33 PM
    The simple way

    answer
    using System;
    class b2
    {
    public static void Main()
    {

    int I,j,k;
    Console.WriteLine("Enter the Range");
    k=int.Parse(Console.ReadLine());
    for (I=1;i<=k;i++)
    {
    for (j=1;j<=i;j++)


    if(j % 2==0)
    Console.Write("0");
    else
    Console.Write("1");
    Console.Write("\n");
    }
    }
    }
    sujeet1's Avatar
    sujeet1 Posts: 1, Reputation: 6
    New Member
     
    #4

    Sep 11, 2011, 05:09 AM
    static void Main(string[] args)
    {


    int a = 1;
    int b = 0;
    int e = 1;
    int f = 0;
    int m = 0;

    Console.WriteLine("enter the number");
    int s = int.Parse(Console.ReadLine());
    for (int I = 1; I <= s; I++)
    {
    for (int j = 1; j <= I; j++)
    {
    Console.Write(a);
    int d = a;
    a = b;
    b = d;
    }
    Console.WriteLine();
    a = e;
    b = f;
    int h = a;
    a = b;
    b = h;
    m = e;
    e = f;
    f = m;
    }

    Console.ReadLine();
    }
    sujeetpasi's Avatar
    sujeetpasi Posts: 1, Reputation: 6
    New Member
     
    #5

    Sep 11, 2011, 11:38 PM
    static void Main(string[] args)
    {

    int a = 0;
    int b = 1;
    Console.WriteLine("enter the hieght");
    int j = int.Parse(Console.ReadLine());
    for (int I = 2; I <= j + 1; I++)
    {
    if (I % 2 == 0)
    {
    a = 1;
    b = 0;
    }

    else
    {
    a = 0;
    b = 1;
    }
    for (int k = 1; k <= I - 1; k++)
    {
    Console.Write(a);
    int c = a;
    a = b;
    b = c;
    }
    Console.WriteLine();
    }
    Console.ReadLine();
    }

    please reply wheather this post was helpful to you

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Binary compounds [ 1 Answers ]

Show formulas for the following compounds: Magnesium nitrate Lead(IV) oxide Copper(II) sulfide

Binary Molecular Compounds [ 1 Answers ]

What is the formula for Oxygen Difluoride and how do I figure it out for others

Binary ionic and binary molecular compounds [ 2 Answers ]

Compare the compositions of binary ionic and binary molecular compounds.

Compare binary files [ 1 Answers ]

Hi there, Where can I find a freeware to compare binary files? (I don't want to compare 2 documents, these are 2 binary files). Thx in advance!


View more questions Search