1------------------
#include
double fun (int n)
{
double f1 = 1.0, f2 = 1.0, f = 2.0, tmp;
double sum = 0.0;
int i;
for (i = 0; i < n; ++i)
{
sum += f2/f;
tmp = f1;
f1 = f2;
f = f + f2;
f2 = f1+tmp;
}
return sum;
}
int main(void)
{
int n;
printf("Enter number:");
scanf("%d", &n);
printf("%f\n", fun(n));
return 0;
}
2-----------------------------------
#include
#include
void invert(char str1[])
{
int a, b;
char c;
for (a=0, b=strlen(str1);a {
c=str1[a];
str1[a]=str1[b-1];
str1[b-1]=c;
}
printf("%s\n", str1);
}
int main(void)
{
char str[128];
printf("INPUT:");
scanf("%s", str);
invert(str);
printf("%s\n", str);
return 0;
}
3----------------------------
#include
int fun(int n)
{
int i = n;
int sum = 1;
for (; i > 0; --i)
sum*=i;
return sum;
}
int main(void)
{
int i;
double sum = 1.0;
for (i = 2; i <= 10; ++i)
{
if (i%2==0)
sum += (-1)*(1.0/fun(i));
else
sum += (1.0/fun(i));
}
printf("%f\n", sum);
return 0;
}
20分也没人做的
没分没人做的。
1