#include <stdio.h>
void printline(char c); /* propotypes */
void value(float, float, int);
main()
{
float principal, inrate;
int period;
printf("Enter principal amount, interest");
printf("rate, and period \n");
scanf("%f %f %d",&principal,&inrate,&period);
printline('='); /*why must be use '' and can not use "" symbol???*/
value(principal,inrate,period);
printline('=');
}
void printline(char ch)
{
int i;
for(i = 1; i <= 52; i++)
printf("%c",ch);
printf("\n");
}
void value(float p, float r, int n)
{
int year;
float sum;
sum = p;
year = 1;
while(year <= n)
{
sum = sum * (1+r);
year += 1;
}
printf("%f\t%f\t%d\t%f\n",p,r,n,sum);
}
转载于:https://my.oschina.net/u/241930/blog/402196