# Thread: newbie- need help with triangular #

1. ## newbie- need help with triangular #

Trying to figure out an exercise out of a text I've got.
Supposed to use the formula:
Triangular number = n(n+1)/2

I now need to create something that will allow a user to enter initial, ending, and step values. i.e. 1 11 2 (this would give me an output of 1, 3, 5, 7, 9, 11)

How do I go about using scanf, and a for loop to do this? Then I want to display it as a simple little table. i.e. triangular number
_______________
1
3
5
7
9
11

Probably something simple I have just overlooked...or too many hours at the office has my mind swimming.
I appreciate any help pointing me in the right direction.

Thanks.

2. Hope this code solves ur problem

Code:
```#include <stdio.h>

int main()
{
int initial_value,end_value,step_value,i;

printf("\nEnter the Initial, End & Step Values\n");
scanf("%d %d %d",&initial_value,&end_value,&step_value);

for(i=initial_value;i<=end_value;i=i+step_value)
printf("\n%d",i);

return 0;
}```

3. ## Much help...

That helped alot...I was on the right track...just forgot one thing.

So now a buddy and I are trying to figure out a couple of others.

1. I'm trying to create a factorial table such as
5! = 5x4x3x2x1 =120. What I want to do is just create a loop that uses scanf to ask a user to input the number they want the factorial of i.e. 6 and then the program will display 6!. Can anyone show a simple loop to do that?

2. Want to use only int to take an integer that is entered i.e. 1234, then makes the sum of those digits (10). How do I do this one? Thanks again...

4. ## One down...

Ok...I got my factorial program all figured out.... now need to figure out how to strip those digits and add them.

5. heres a clue.....

1234%10=4

6. Factorial of a number:

Code:
```#include <stdio.h>

int main()
{
int num,i,j=1;

printf("Enter the number whose fatorial has to be found: ");
scanf("%d",&num);

for(i=1;i<=num;i++)
{
j=j*i;
}

printf("Fatorial is %d",j);

return 0;
}```

sum of a 4 digit number

Code:
```#include <stdio.h>

int main()
{
int num,j,i;

printf("Enter a 4 digit number: ");
scanf("%d",&num);

for(i=1;i<=4;i++)
{
j=num%10;
num=num/10;
printf("%d",j);
}

return 0;
}```

7. ## starting to make sense...

I understand the 1234%10....
I'm just trying to figure out how to keep stripping those numbers...
ie. I've got 1234%10=4, now I need to get 123%10, etc. and all them together...that where my struggle is. I'm sure it is just something simple....I'm probably just realizing how easy it is and making the logic to difficult.

Silver....isn't the one you posted for sum of 4 digits just one that will reverse digits?

Thanks for the help and hints everyone...it's coming together now.

8. Sorry m8. Just got a little confused with the question.

Try this

Code:
```#include <stdio.h>

int main()
{
int num,j,i,k=0;

printf("Enter a 4 digit number: ");
scanf("%d",&num);

for(i=1;i<=4;i++)
{
j=num%10;
num=num/10;
k=k+j;

}

printf("%d",k);

return 0;
}```

9. Thanks for the help... I had acutally figured that piece out not long ago. I'm going to try some other stuff this weekend. If I get in a bind....you will see me again.

Thanks alot.