当前位置: 代码迷 >> C语言 >> 新鸟求助!运行居然是空白.郁闷了哦
  详细解决方案

新鸟求助!运行居然是空白.郁闷了哦

热度:279   发布时间:2008-01-22 21:43:57.0
进的帮帮忙撒.嘿嘿.
----------------解决方案--------------------------------------------------------
/*下面这个结果是正确的*/ /*你什么编译器*/
#include "stdio.h"
#include "conio.h"
#include<math.h>

int main()
{
    float amount;
    float zijin = 1000.0 ;
    float lixi= 0.05 ;
    int year ;

     printf ("%4s%21s\n","Year", "Amount on deposit") ;

    for (year=1;  year<=10; year++){
      
         amount = zijin * pow(1.0+lixi, year);

      
    printf ("year=%d  amount=%2.2f\n",year, amount );



    }



    getch();



}
----------------解决方案--------------------------------------------------------
大哥   你高手哦!
整的乱七八糟!!!
----------------解决方案--------------------------------------------------------
main()
{
    float amount;
    float zijin = 1000.0 ;
    float lixi= 0.05 ;
    int year ;

     printf ("%4s%21s\n","Year", "Amount on deposit") ;

    for (year=1;  year<=10; year++){
      
         zijin = zijin * (1+0.05);

      
    printf ("year=%d  amount=%2.2f\n",year, zijin);



    }



    getch();



}
Year    Amount on deposit
year=1  amount=1050.00
year=2  amount=1102.50
year=3  amount=1157.62
year=4  amount=1215.51
year=5  amount=1276.28
year=6  amount=1340.10
year=7  amount=1407.10
year=8  amount=1477.46
year=9  amount=1551.33
year=10  amount=1628.89
----------------解决方案--------------------------------------------------------
#include "stdio.h"
#include "math.h"
int main()
{
    double amount;
    double zijin = 1000.0 ;
    double lixi= 0.05 ;
    int year ;
    printf ("%4s%21s\n","Year", "Amount on deposit") ;
    for (year=1;  year<=10; year++)
    {
        amount = zijin * pow(1.0+lixi, year);
        printf ("%4d%17.2f\n",year, amount );
    }
    getch();
}
----------------解决方案--------------------------------------------------------
#include "stdio.h"
#include "conio.h"
#include<math.h>

int main()
{
    double amount;
    double zijin = 1000.0;
    double lixi= 0.05;
    int year;

     printf ("%4s%21s\n","Year","Amount on deposit");

    for (year=1;year<=10;year++){

    amount = zijin*pow(1.0+lixi,year);


    printf ("%4f%21.2f\n",year,amount );



    }



    getch();



}
这个是运行结果,说乱七八糟是指的结果比较乱,而不是程序有问题,呵呵,

[[italic] 本帖最后由 devil_v6 于 2008-1-25 10:52 编辑 [/italic]]
----------------解决方案--------------------------------------------------------
上面的程序用的是xianshizhe111大哥的程序
应该是在输出结果的时候将小数点后的位数控制一下就可以了
用15楼的方法printf ("%4d%17.2f\n",year, amount );
结果如下:
----------------解决方案--------------------------------------------------------
  相关解决方案