//方法一:用for循环表示
1 #include<stdio.h> 2 int main() 3 { 4 int i; 5 int t = 1; 6 7 for(i=2;i<=5;i++) 8 { 9 t = i * t; 10 } 11 printf("1*2*3*4*5=%d\n",t); 12 13 return 0; 14 }
//方法二:用while循环表示
1 #include<stdio.h> 2 int main() 3 { 4 int i,t; 5 t = 1; 6 i = 2; 7 8 while(i<=5) 9 { 10 t = t * i; 11 i = i + 1; 12 } 13 printf("%d\n",t); 14 15 return 0; 16 }