(1)
#include "stdio.h"
#include "math.h"
int main(int argc,char *argv[]){
float m,r;
int n;
printf("Please input, the number of the principal and interest rates in turn.\n");
if(scanf("%f,%d,%f",&m,&n,&r)!=3 || m<0 || n<0 || r<0){
printf("Input error, exit...\n");
return 0;
}
printf("Interest: %.0f\n",m*(pow(1+r,n)-1)*.8);
return 0;
}
运行样例:
(2)
#include "stdio.h"
int main(int argc,char *argv[]){
float h,r;
printf("Please enter r & h(R:) in turn.\n");
if(scanf("%f,%f",&r,&h)!=2 || r<0 || h<0){
printf("Input error, exit...\n");
return 0;
}
printf("The volume is: %.2f\n",3.14/3*h*r*r);
return 0;
}
运行样例: