C++难题,请指教!

来源:百度知道 编辑:UC知道 时间:2024/05/06 07:24:52
1.从键盘任意输入一串字符,再任意输入一个指定字符。从字符串中删除该指定字符,并统计该字符在串中出现的次数。
2.用牛顿迭代法计算方程f(x)=0的近似根,要求精度为10-5,方程f(x)=0由同学自己选择。
3.编程计算S=1!+2!+3!+…+n!,n的值由键盘输入,计算n!的函数设计成递归函数。

1、
#include "stdafx.h"
#include <iostream>
using namespace std;
#include <cmath>
#include <cstring>
int find_swap_str(char source [],char dest [],char replace[])
{int count=0,temp=0;
for (int i=0;i<strlen(source);i++)
{int j=0;
while (dest[j]==source[i]&&j!=strlen(dest))
j++,i++;
if (j==strlen(dest))
{count++;i--;
temp=i-strlen(dest)+1;//begin to replace
if(strlen(dest)==strlen(replace))
for(int m=0;m<strlen(replace);m++,temp++)
source[temp]=replace[m];
}
}
return count;
}
2.那个式子我好久不用了 。你能给我提供下?
3、
int fun(int n)
{if(n==0)return 1;
if(n==1)return 1;
if(n<0)
{cout<<"input error"<<endl;return -1;}
if (n>0)return n*fun(n-1);
}
}
void main()
{
int n;cin>>n;double s=0;
for(int i=1;i<=n;i++)
s=s+1/fun(n);