題8000022012,求一個整數任意次方的最後三位數。
#include#include int main() { int m,n; scanf("%d %d",&m,&n); int i; int sum = 1; for(i=0;i 1000) sum = sum%1000; sum = sum * m; } printf("%d\n",sum%1000); return 0; }
#include#include #include int main() { double pi = 0; double i = 1.0; do { pi+= 1/i; if(i>0) i = -(i+2); else i = fabs(i) +2; }while(fabs(1/i)>1e-6); printf("%.6lf\n",4*pi); return 0; }
#include#include #include int main() { double num; scanf("%lf",&num); int count = 0; int number ; number = (int)(fabs(num)); while(number) { count++; number = number / 10; } printf("%d\n",count); return 0; }
#include#include #include int main() { double x0,x1=0,x2=0,fx0,fx1,fx2;//x1,x2未端點,x0為中點,浮點型數據 //判斷區間是否有解 printf("請輸入端點x1,x2:\n"); scanf("%lf %lf",&x1,&x2); printf("x1:%lf\n",x1); printf("x2:%lf\n",x2); fx1=2*x1*x1*x1-4*x1*x1+3*x1-6; fx2=2*x2*x2*x2-4*x2*x2+3*x2-6; if(fx1*fx2>0) { printf("have no anwser\n"); exit(0); } //二分法求解 do { x0=(x1+x2)/2; fx0=2*x0*x0*x0-4*x0*x0+3*x0-6; if (fx0*fx1<0)//在該區間 { x2=x0;//調整端點位置 fx2=fx0; } else { x1=x0; fx1=fx0; } } while (fabs(fx0)>1e-6);// 這裡精度太小可能跟文檔答案有偏差 printf("方程的根%.2lf",x0); return 0; }
#include#include #include int main() { double num; scanf("%lf",&num); double x1,x2=1.0; do { x1 = x2; x2 = 0.5*(x1 + num/x1); }while(fabs(x1-x2)>1e-5); printf("%lf\n",x1); return 0; }
#include#include #include int isCompleteNum(int num) { int i; int ans = num; for(i=1;i<= num/2;i++) { if(num%i==0) ans-= i; } if(ans == 0) return 1; else return 0; } void PrintFactor(int num) { printf("%d=",num); int i,j=0; int factor[20]; for(i=1;i<=num/2;i++) { if(num%i==0) factor[j++]=i; } for(i=0;i 題8000010008百分制成績轉換
#include#include int main() { int grade; scanf("%d",&grade); printf("%c\n",grade); switch(grade/10) { case 10: case 9: printf("A\n");break; case 8:printf("B\n");break; case 7:printf("C\n");break; case 6:printf("D\n");break; default:printf("E\n"); } return 0; }
題8000010007 輸入日期,判斷是這一年的第幾天
#include#include int isLeapYear(int year) { if((year%4==0&&year%100!=0) ||(year%400==0)) { return 1; } else { return 0; } } int main() { int year,month,day; scanf("%d-%d-%d",&year,&month,&day); int dayOfMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31}; int totalDays = 0,index; for(index=0;index 2)) { totalDays++; } printf("%d-%d-%d\n",year,month,day); printf("total days = %d",totalDays); return 0; }