# Factorial and Prime Problem using functions

• 02-17-2010
akosikuya21
Factorial and Prime Problem using functions
Can any correct this programming please need help on this 1..... cant really get this one....thank you

Code:

```#include<stdio.h> int Fact(int); int Prime(int); int main() { printf("Factorial %d\n", Fact(3)); printf("Prime %d", Prime(3)); Return 0; } int Fact(int n) {     int i;     for(i=1;i<=n;i++) {     i*n; } return i; } int Prime(int n) {     int i;     for(i=1;i<=n;i++) {     n/=n; } return i; } }```
it made me go nosebleed over my shirt of thinking...btw im still new in Programming
• 02-17-2010
ZuK
Code:

```int Fact(int n) {     int i;     for(i=1;i<=n;i++) {         i*n; // this doesn't do anything just multiplys i by n and discards the result     }     return i;  }```
try like this
Code:

```int Fact(int n) {     int i; ret = 1;     for(i=1;i<=n;i++) {         ret*=i;     }     return ret;  }```
Kurt
• 02-17-2010
akosikuya21
hmmm does it give the results of 6 cause the factorial of 3 is like 6:Answer"3x2x1" but output should be 6..... but do you have clue on the Prime part it took the hell out of me T.T
• 02-17-2010
anon
The prime part doesn't make any sense (you just keep dividing the number by itself).

Instead you should perform trial divisions with values up to the number you are testing (seeing if number is divisible with any number less than it or not - using modulus).