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 9318091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:01:49+00:00 2026-06-19T03:01:49+00:00

I am trying Pascal Triangle solution in C, based on below formula: I wrote

  • 0

I am trying Pascal Triangle solution in C, based on below formula:

Formula for Pascal tree

I wrote the below code based on above formula:

#include <stdio.h>
#include <stdlib.h>

int pascalTriangle(int row, int col);

int main()
{
  int row, col;

  printf("Enter the row [0 to n]: ");
  scanf("%i", &row);
  printf("Enter the column [0 to m]: ");
  scanf("%i", &col);

  if(col > row) {
    printf("Error: column can be less than or equal to row\n");
    exit(1);
  }

  printf("Value = %i\n", pascalTriangle(row, col));
  return 0;
}

int pascalTriangle(int row, int col)
{
  int value[100];
  value[0]=1;
  int i=1;
  if(row==0 || row==col || col==0) {
    return value[0];
  } else {
row=row+1;
    while(i<=col) {
        printf("i = %i\trow = %i\tcol = %i\n", i, row, col);
        value[i]='\0';
        value[i]=(value[i-1]) * ((row-i)/i);
        printf("value[%i] = %i\tvalue[%i] = %i\n", i-1, value[i-1], i, value[i]);
        ++i;
    }
    return value[i-1];
  }
}

Here, upto some extent it is giving proper O/P. But, for many I/Ps I found wrong answers. I am unable to find the logical error, as on paper the logic is giving expected O/P. Example:- I give row=4 & col=2, O/P should be 6 but getting 4 as O/P.

Please help!!

  • 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-06-19T03:01:50+00:00Added an answer on June 19, 2026 at 3:01 am

    The line

    value[i]=(value[i-1]) * ((row-i)/i);
    

    is wrong. row - ineed not be divisible by i (it generally isn’t). You need to first multiply and then divide,

    value[i]=(value[i-1] * (row-i))/i;
    

    (parentheses not necessary since they are implicitly placed thus), but then you have earlier overflow, so for larger values of row, compute the gcd,

    int g = gcd(row - i, i)
    

    and divide (row - i) / g, value[i-1]/(i/g)and multiply the results of these.

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

Sidebar

Related Questions

I am trying to write a hangman code on scala. So, I wrote the
I've been trying to calculate total of 1500th row in pascal triangle in c++.
I am trying to convert a C code to Delphi/pascal, but somehow I cannot
I'm trying to make a Pascal Triangle print to a hundred rows, but Java's
i'm trying to make a very simple YACC parser on Pascal language which just
I'm new to Pascal and I am trying to write a simple program, but
I'm trying to format strings in XSLT that needs to be in pascal case
I am trying to write a procedure in Inno setup code using default values
I have written a function for returning the next row in Pascal's triangle given
I am trying to build a script using Pascal scripting to return the name

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.