# help with my algortihm

Page 1 of 1

## 3 Replies - 408 Views - Last Post: 04 October 2012 - 12:00 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294196&amp;s=19177659290ec2cafb3e11fca00a678f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 5
• Joined: 03-October 12

# help with my algortihm

Posted 03 October 2012 - 10:23 PM

I'm designing a code for class on factorials of long, short, long integers and floats but somewhere my algortihm is messing up can someone help me. Here's my code:

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

int fact(int a)
{
int i, n, result = 1;

for (i = 1; i <= n; i++)
result = result * i;

printf("Factorial of %d = %d\n", a, result);

}

int main(int argc, char * argv[])
{
int num;
printf("Enter a number:\n");
scanf("%d", &num);
fact(num);

system("PAUSE");
return 0;
}
```

This post has been edited by Salem_c: 03 October 2012 - 11:41 PM
Reason for edit:: added [code][/code] tags - learn to use them yourself

Is This A Good Question/Topic? 0

## Replies To: help with my algortihm

### #2 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: help with my algortihm

Posted 03 October 2012 - 10:28 PM

You aren't using the value of 'a' anywhere in your code until you print the result. N=0.
Factorials are: number x number - 1 x number - 2 x number - 3 and so on until it reaches 1.

Reputation: 0
• Posts: 5
• Joined: 03-October 12

## Re: help with my algortihm

Posted 03 October 2012 - 11:34 PM

DimitriV, on 03 October 2012 - 10:28 PM, said:

You aren't using the value of 'a' anywhere in your code until you print the result. N=0.
Factorials are: number x number - 1 x number - 2 x number - 3 and so on until it reaches 1.

Got it. Thanks a lot. How would make it so the printed value is a short integer or long integer but my compiler is giving strange numbers for those values

### #4 Skydiver

• Code herder

Reputation: 6220
• Posts: 21,471
• Joined: 05-May 12

## Re: help with my algortihm

Posted 04 October 2012 - 12:00 AM

Show us your code where you have a short integer and a long integer. Show us, as well, the "strange numbers" that you are getting.