Chinaunix首页 | 论坛 | 博客
  • 博客访问: 99408
  • 博文数量: 102
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1011
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-15 13:58
个人简介

普普通通一个人

文章分类

全部博文(102)

文章存档

2018年(1)

2015年(13)

2014年(88)

我的朋友

分类: C/C++

2014-02-24 14:51:35


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. //计算阶乘的函数
  3. int factorial(int);

  4. int main(){
  5.     int x;
  6.     char start;
  7.     printf("start?(y/n): ");
  8.     scanf("%c", &start);
  9.     while (start == 'y'){
  10.         fflush(stdin);
  11.         printf("enter a number: ");
  12.         scanf("%d", &x);
  13.         factorial(x);
  14.         fflush(stdin);
  15.         printf("\nstart?(y/n): ");
  16.         scanf("%c", &start);
  17.     }
  18.     return 0;
  19. }
  20. //计算阶乘的函数
  21. int factorial(int a){
  22.     int i = a - 1;
  23.     for (i; i > 0; i--)
  24.         a = a * i;
  25.     printf("x! = %d", a);
  26.     return 0;
  27. }

阅读(207) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~