用C语言带我学一下这倒编程题
毕业设计
1
-
#include <stdio.h> #include <math.h> #define N 20 double shulie(int n) { int s[N] = { 0 }, i; double r1; s[0] = 0; s[1] = 0; s[2] = 1; for (i = 3; i < n; i++) { s[i] = s[i - 1] + s[i - 2] + s[i - 3]; } r1 = 0; for (i = 0; i < n; i++) { r1 += sqrt((double)s[i]); } return r1; } int main() { int n; double r; scanf("%d", &n); r = shulie(n); printf("%f", r); return 0; }
-
#include<stdio.h> float shulie(int n){ float s[n],r1; int i,j; s[0]=0; s[1]=0; s[2]=1; for(i=3;i<n;i++){ s[i]=s[i-1]+s[i-2]+s[i-3]; } r1=0; for(j=0;j<n;j++){ r1=r1+sqrt(s[j]); } return r1; } int main() { int n; float r; scanf("%d",&n); r=shulie(n); printf("%.6f",r); return 0; }
发表回复