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,,

Recommended Answers

All 10 Replies

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.

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...

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

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");
 }
}
commented: I like this code. Thank you! +1

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? ;)

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.

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. 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 with

getche();

your could very well use the standard getchar().

commented: I guess we have another C++ consultant in making... ;) - ~s.o.s~ +14

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.