User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,771 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,541 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 14161 | Replies: 14
Closed Thread
Join Date: May 2005
Posts: 80
Reputation: indianscorpion2 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Need Help With Printing Pascal's Triangle In C

  #1  
May 16th, 2005
hi my name is srikanth.i have been trying to develop a source code to print the pascal's triangle for the past three days.i have'nt had any success.i would be greatly obliged if anyone could give me a simple source code to print the pascal's triangle in C.
AddThis Social Bookmark Button
 
Join Date: Feb 2005
Posts: 461
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Need Help With Printing Pascal's Triangle In C

  #2  
May 16th, 2005
If you've been working on it for 3 days, surely you have developed a starting point. Why don't you post your code, indicate specifically what's not working, and someone will help you.
 
Join Date: May 2005
Posts: 80
Reputation: indianscorpion2 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

need a source code in C to print pascal's triangle

  #3  
May 16th, 2005
hi i am a student of computer science.i am a beginner.i am looking for a simple source code in C to print the pascal's triangle.the user should have the option to enter the number of rows he requires to view.i would be obliged if anyone could help out here.
 
Join Date: Feb 2005
Posts: 461
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: need a source code in C to print pascal's triangle

  #4  
May 16th, 2005
You didn't like the answer the first time so you post it again?
 
Join Date: May 2005
Posts: 80
Reputation: indianscorpion2 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

i need an algorithm to print pascal's triangle

  #5  
May 18th, 2005
i am a student of computer science.i require an algorithm to print the pascal's triangle.
 
Join Date: Apr 2004
Posts: 3,462
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need Help With Printing Pascal's Triangle In C

  #6  
May 18th, 2005
Merged threads: indianscorpion2, please don't start new threads with the same topic in a relatively short period of time (a couple days). If you haven't had any success, how about starting with a failed attempt?
 
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Need Help With Printing Pascal's Triangle In C

  #7  
May 18th, 2005
Here's the mathematical way to do it. But if this is homework, your teacher is probably looking for the brute force way of doing it. I won't show you that one because half the fun is figuring things out for yourself. The other half is writing the code to do it.
#include <iostream>

double factorial(double n)
{
  return (n > 1) ? n * factorial(n - 1) : 1;
}

double ncr(int n, int r)
{
  return factorial(n) / (factorial(r) * factorial(n - r));
}

int main()
{
  std::cout.setf(std::ios::fixed, std::ios::floatfield);
  std::cout.precision(0);

  for (int i = 0; i < 15; i++) {
    for (int j = 0; j <= i; j++)
      std::cout << std::right << ncr(i, j) << ' ';
    std::cout << std::endl;
  }
}
 
Join Date: Jul 2005
Posts: 3
Reputation: uzone24 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
uzone24 uzone24 is offline Offline
Newbie Poster

Re: need a source code in C to print pascal's triangle

  #8  
Jul 28th, 2005
Originally Posted by indianscorpion2
hi i am a student of computer science.i am a beginner.i am looking for a simple source code in C to print the pascal's triangle.the user should have the option to enter the number of rows he requires to view.i would be obliged if anyone could help out here.

#include<stdio.h>
void main()
{
int ary[i][j],n;

printf("\nEnter the number of rows:");
scanf("%d",&n);

 for(i=0;i<n;i++)
 {
  for(j=0;j<=i;j++)
  {
   if(j==0!!j==1)
   ary[i][j]=1;
   else
   ary[i][j]=ary[i-1][j-1]+ary[i-1][j];
  }
 }

 for(i=0;i<n;i++)
 {
  printf("\n"); 
  for(j=0;j<=i;j++)
  {
   printf("%d",ary[i][j]);
  }
 }
}
<< moderator edit: added [code][/code] tags >>
 
Join Date: Sep 2004
Posts: 6,050
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 416
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: Need Help With Printing Pascal's Triangle In C

  #9  
Jul 28th, 2005
uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
Member of: Beautiful Code Club.
 
Join Date: Jul 2005
Posts: 3
Reputation: uzone24 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
uzone24 uzone24 is offline Offline
Newbie Poster

Re: Need Help With Printing Pascal's Triangle In C

  #10  
Jul 29th, 2005
Originally Posted by Narue
uzone24, one reason I haven't moderated your post is because the original question was posed several months ago. But we don't give answers to homework without effort on the student's part. The other reason is because your code both sucks and is horribly broken, so if someone bothered to turn it in, they would surely fail.
Narue can u elaborate on reasons y my code sucks as well wud fail ??
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 4:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC