现在的位置: 首页 > 综合 > 正文

任意位小数四舍五入

2013年09月12日 ⁄ 综合 ⁄ 共 562字 ⁄ 字号 评论关闭
Code:
  1. #include <stdio.h>  
  2. #include <conio.h>  
  3. double change(double x,int n);  
  4. int func(int n);  
  5. int main()  
  6. {  
  7.     double x;  
  8.     int c;  
  9.     puts("任意位小数:");  
  10.     scanf("%lf",&x);  
  11.       
  12.     puts("保留多少位小数:");  
  13.      scanf("%d",&c);  
  14.       
  15.     printf("结果是%lf",change(x,c));  
  16.       
  17.     getch();  
  18.     return 0;  
  19. }  
  20.   
  21.   
  22. double change(double x,int n)  
  23. {  
  24.        x=int(x*func(n)+0.5);  
  25.        x=x/func(n);  
  26.        return x;  
  27. }  
  28.   
  29. int func(int n)  
  30. {  
  31.     if(n==1)  
  32.     {  
  33.             return 10;  
  34.     }  
  35.     n=func(n-1)*10;  
  36.       
  37.     return n;  
  38. }  

 - -我怎么看到这个程序,就很兴奋呢。。

 

 

 

 

抱歉!评论已关闭.