Thread: Easy Question
View Single Post
Old 2009-09-30, 23:34   #1
Unregistered
 

2·52·131 Posts
Default Easy Question

I'm a complete noob when it comes to programming in c, but you have to start somewhere. I ran into a question about factorials. Can you use "n!"? It didnt work for me, I instead went about it the long way,

# include <stdio.h>

int main (void)
{

int n, n1 = 1, n2 = 2, n3 = 3, n4 = 4, n5 = 5, n6 = 6, n7 = 7, n8 = 8, n9 = 9, n10 = 10, nResult;

printf("-n- -n!\n\n");


printf( "%i %2i\n" , n1 , nResult = n1);
printf( "%i %2i\n", n2, nResult = n1 * n2);
printf( "%i %2i\n", n3, nResult = n1 * n2 * n3);
printf( "%i %2i\n", n4, nResult = n1 * n2 * n3 * n4);
printf( "%i %2i\n", n5, nResult = n1 * n2 * n3 *n4 * n5);
and so on....
}


Whats an easier way?
  Reply With Quote