Coder Social home page Coder Social logo

c-pattern's Introduction

EX-NO-3 Pattern

Aim:

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

Equipment Required:

Microsoft Visual Studio 2022 (or Lower) or Any other C# compiler.

Algorithm:

Step 1:

Create a new Class named program.

Step 2:

Declare two variables of int data type one to store the input from user for no.of rows snd another the value for printing.

Step 3:

Get the number of rows from the user.

Step 4:

Using for loop print the rows and columns and space.

Step 5:

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

Step 6:

Otherwise use else to print the inner value val = val * (i - j + 1) / j

Step 7:

Print the program.

Step 8:

End of the Program.

Program:

Developed By: Mohan Raj
Reg No: 212221230065
using System;
namespace Pattern
{
    public class parogram
    {
        public static void Main(string[] args)
        {
            int row, c = 1;

            Console.Write("Enter number of rows: ");
            row = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < row; i++)
            {
                for (int j = 1; j <= row - i; j++)
                    Console.Write(" ");
                for (int j = 0; j <= i; j++)
                {
                    if (j == 0 || i == 0)
                        c = 1;
                    else
                        c = c * (i - j + 1) / j;
                    Console.Write("{0} ", c);
                }
                Console.WriteLine();
            }
        }
    }
}

Output:

image

Result:

Hence, a C# program for a pascal's triangle is executed successfully.

c-pattern's People

Contributors

archanasharikalharinarayanan avatar mohanraj2004 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.