http://acm.hzau.edu.cn/problem.php?id=1099
Test instructions
Enter two integers l and N, which represent the number of reserved decimal places for the radius and output.
The area of the output circle, preserving n decimal places.
It starts with a restraining character and then finds that it will be rounded up when it is retained, so no.
Knowledge mainly uses the floor function (the largest integer (double) type that returns no greater than the parameter value) and sprintf.
AC Code:
1#include <stdio.h>2#include <string.h>3#include <math.h>4 #definePI 3.14159265355 intMainvoid)6 {7 Doublel;8 intN;9 while(SCANF ("%lf%d", &l, &n)! =EOF)Ten { One if(!l) printf ("0"); A Else if(!n) printf ("%.LF", Floor (pi*l*l)); - Else - { the Charstr[ +]; -sprintf (str,"%.*LF", n +2, pi*l*l); -printf"%.LF.", Floor (pi*l*l)); - for(inti =0; ; i++) + { - if(Str[i] = ='.') { + for(intj = i +1; J <= i + N; J + +) Aprintf"%c", Str[j]); at Gotoend; - } - } - end:; - } -Putchar ('\ n'); in } - return 0; to}
C Problem of freshman race of Huazhong Agricultural University