Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:34:34+00:00 2026-05-17T23:34:34+00:00

The following code snippet prints the Pascals triangle,I have got this snippet from the

  • 0

The following code snippet prints the Pascals triangle,I have got this snippet from the internet but I am unable to get the formula for bin.If anyone can help me out with it I would be thankfull\

#include<stdio.h>
int main()
{
    int bin=1,p,q=0,r,x;
    clrscr();
    printf("Rows you want to input:");
    scanf("%d",&r);
    printf("\nPascal's Triangle:\n");
    while(q<r)
    {   
        printf("ROW %d",q);
        for(p=40-3*q;p>0;--p)
        printf(" ");
        for(x=0;x<=q;++x)
        {
            if((x==0)||(q==0))
            bin=1;
            else
            bin=(bin*(q-x+1))/x;
            printf("%6d",bin);
        }
        printf("\n");
        ++q;
    }
    getchar();
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:34:35+00:00Added an answer on May 17, 2026 at 11:34 pm

    Ok, let’s take a look.
    The actuall formula is the inner for loop:

        for(x=0;x<=q;++x)
        {
            if((x==0)||(q==0))
              bin=1;
            else
              bin=(bin*(q-x+1))/x;
            printf("%6d",bin);
        }
    

    q represents the row of the pascal triangle, starting at the top.
    x represents the element number in the row. Since in row 1 there will be 1 element in row 2 two elemnts.
    So the for(x=0;x<=q;++x) makes sense.

    now to the if clause if((x==0)||(q==0)). If x is 0 than we are at the left side of the triangle or beginning of the triangle row, which is always 1. If q is 0 than obviosly this is the first row of the triangle (starting at the top) which is also always 1. Since there is the only one element.

    now to the else clause, which is probably the most interesting part:

        else
          bin=(bin*(q-x+1))/x;
    

    The first time we get in to this clause is after q was 0 and x was 0 at the start of the loop and was set to 1. This is important since bin was defined outside of the for loop and keeps the value from iteration to iteration. So now x is 2 and bin is 1. Again q represents the row number and the length of the row. To understand this you should look at the wikipedia page of the pascal’s triangle. Especially the part with

    Calculating an individual row or
    diagonal by itself

    there you will find the formula written down again. The important word here are factorials. Also looking at the article about the pascal matrix might be helpful.
    I’ll try to explain it but (i hate when somebody says that) you have to see it. Take a look of the diagonals of the pascal triangle and at the inner part of the formula (q-x+1). Now compute the values which you will alsways get for every diagonal. You see a pattern? I hope now things start to make sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say I have the following desire, to simplify the IConvertible's to allow me
I need to solve the following question which i can't get to work by
I'm doing some changes on my routes, and suddenly the following is appearing in
I am attempting to pull some information from my tnsnames file using regex. I
My question is about memory use and objects in actionscript 2. If I have
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
I would like to update my SQL lite database with the native update-method of
I'm trying to build a C++ extension for python using swig. I've followed the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.