954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

pascal triangle?

hi, nu member hir, just hav some question regarding this output:

1
          232        
         34543
        4567654
       567898765
      67890109876
     7890123210987
    890123454321098
   90123456765432109
  0123456789876543210

numbers that are alligned with 1 are

3
5
7
9
1
3
5
7
9

these are the middle numbers...

does anybody know how to do this in c language? or to look for its formula? tnx alot,,

stringgader
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
does anybody know how to do this in c language? or to look for its formula? tnx alot,,


Yes, many of us know how to do this. The question is: do you? Or can you figure it out?

If you need help, asking specific questions and posting code you've tried will get excellent answers.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

no i cant, thats why im asking for someone hu can help me do thiis ,, its actually a problem,, twas given by our instructor and wants us to figure it out,, thats why ide like to gather any idea or information regarding this thing,,, tnx for the reply...

stringgader
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

by the way,, im only new to this programming thing,, tnx again

stringgader
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

TRY THIS OUT

#include<stdio.h>
main()
{
 int i,j,k;
 printf("\n");
 for(i=1;i<=10;i++)
 {
  for(j=1;j<=31-i;j++)printf(" ");
  for(j=i,k=(2*i-1)/2+1;k;j++,k--)
  {
    if(j==10)j=0;
    printf("%d",j);
  }
  for(j-=2,k=(2*i-1)/2;k;j--,k--)
  {
   if(j==-1)j=9;
   printf("%d",j);
  }
  printf("\n");
 }
}
goutham_see
Newbie Poster
7 posts since Feb 2007
Reputation Points: 11
Solved Threads: 0
 
TRY THIS OUT

goutham, around here we want the poster to find the answer. We help them with their code, we don't do their homework for them.

stringgader, read the above. In order to get this problem from your instructor, you must know something about code. This can't possibly be your first program.
by the way,, im only new to this programming thing,, tnx again
Duh, really? ;)

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 
no i cant, thats why im asking for someone hu can help me do thiis ,, its actually a problem,, twas given by our instructor and wants us to figure it out,, thats why ide like to gather any idea or information regarding this thing,,, tnx for the reply...

Go back and read the thread link that I posted, it contains the answer to your problem. If you don't understand the posted code to that thread then I doubt you are ready for the course you are taking. The proglem is a little too advanced for someone completly new to programming and C language in particular.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

ei,, tnx again for your replies,,,
yup im only new to this, im already working on this for 2 weeks,, this is my code:

#include<stdio.h>
int value,count1,count2,count3,temp;
main()
 {
 clrscr();
 temp=1;
                   printf("Enter number of rows:");
                   scanf("%d", &value);
 
 
 for(count1=1; count1<=value; count1++)
 printf(" ");
 {
  for(count2=value; count2>=count1; count2--)
  printf(" ");
  for(count3=1; count3<=temp; count3++)
  printf("%d",count1,count2,count3);
 printf("\n");
 temp+=2;
 }
 getche();
 }


but, my output is this:

1
               222
              3333
             44444
            555555
etc......



i bet i got a wrong formulation for this stuff, and my deadline is on saturday,, hoping 4 ur nice consideration... tnx alot

stringgader
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

@ stringgader. The code that goutham_see posted for you, works very well. Why don't you compare his with yours and learn what is not working with yours?.

In your last post I see that you make the declaration of variables ALL Global. I don't think that's what you want even when is going to work. What you want to do is to declare them after the left bracket in main, in this case.

The function:
clrscr(); is not necesary there. Is not doing anything for your, and above anything else, it makes your code not portable, which is something that you should always shoot for.

Same withgetche(); your could very well use the standard getchar().

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

ei guys,,, i got it,, thank you so much,,,
u guys are gooood...

stringgader
Newbie Poster
6 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You