Code Monkey home page Code Monkey logo

c-pattern's Introduction

Pattern

Aim:

To write a C# program for a pascal's triangle

Equipment Required:

C# Compiler or visual studio

Algorithm:

Step 1:

Initialize the necessary attributes.

Step 2:

Get the limit from the user.

Step 3:

using for loop print the rows and columns and space.

Step 4:

Check the first and last rows of the triange is 1 using if condition.

Step 5:

Otherwise use else to print the inner value

val = val * (i - j + 1) / j;

Step 6:

Check the program for any error.

if not.

Step 7:

print the program.

Program:

Developed by:R.Vijay
Reg.No:212221230121
using System;
namespace Pascal
{
    public class program
    {
        static void Main(string[] args)
        {
            int rows,i,val=1;
            Console.WriteLine("Enter the number: ");
            rows = Convert.ToInt32(Console.ReadLine());
            for(i=0;i<rows;i++)
            {
                for (int space = 1; space < rows - i; space++)
                {
                    Console.Write(" ");
                }
                    for(int j=0;j<=i;j++)
                    {
                        if (i == 0 || j == 0)
                        {
                            val = 1;
                        }
                        else
                        {
                            val = val * (i - j + 1) / j;
                        }
                    Console.Write(val + " ");
                }
                Console.WriteLine();
            }
        }

    }
}

Output:

output

Result:

Thus,To write a C# program for a pascal's triangle is written and executed.

c-pattern's People

Contributors

archanasharikalharinarayanan avatar vijay21500269 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.